-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tim Clifford
committed
Sep 16, 2020
1 parent
4393d65
commit b76b745
Showing
9 changed files
with
271 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
title: "Drupal 7 Security Module Updates policy" | ||
class: \Drutiny\algm\Audit\D7SecurityModuleUpdates | ||
name: algm:D7SecurityModuleUpdates | ||
tags: | ||
- Drupal 7 | ||
- Security | ||
description: | | ||
It important to keep your site up to date and patched from known security vulnerabilities. | ||
Note that upgrading modules, especially between major versions can introduce | ||
regressions into your site. While its important to maintain a continual update | ||
schedule for your site, regression testing changes is of equal importance. | ||
success: No security updates were found. | ||
failure: >- | ||
{{ updates }} | ||
warning: | | ||
There are modules with available updates. Please consider upgrading as it | ||
reduces the chance of introducing regressions when more urgent security updates | ||
are required. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
title: "Database Analysis" | ||
class: \Drutiny\algm\Audit\DatabaseAnalysis | ||
name: algm:DatabseAnalysis | ||
description: | | ||
Runs a databsae analysis to find out info about the database. | ||
success: | | ||
{{ database_stats }} | ||
failure: Could not find database info. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
title: 'ALGM Drupal 7 SLA audit' | ||
description: 'This audit is for Drupal 7 sites which are under the ALGM SLA' | ||
policies: | ||
# ALGM specific | ||
'algm:HealthCheck': | ||
{ severity: high } | ||
'algm:DrushStatus': | ||
{ severity: normal } | ||
'algm:D7SecurityModuleUpdates': | ||
{ severity: high } | ||
'algm:FileSystemAnalysis': | ||
{ severity: normal } | ||
# D7 | ||
'Drupal-7:NoDuplicateModules': { severity: normal } | ||
'Drupal-7:OverlayModuleDisabled': { severity: normal } | ||
'Drupal-7:BlackListPermissions': { severity: normal } | ||
'Drupal-7:PhpModuleDisabled': { severity: normal } | ||
'Drupal-7:SimpletestModuleDisabled': { severity: normal } | ||
'Drupal-7:StatisticsModuleDisabled': { severity: normal } | ||
'Drupal-7:UpdateModuleDisabled': { severity: normal } | ||
'Drupal-7:XMLSitemapBaseURL': { severity: normal } | ||
'Drupal-7:ZenRegistryRebuild': { severity: normal } | ||
# FS and Database | ||
'fs:largeFiles': { severity: normal } | ||
'Drupal:largeFiles': { severity: normal } | ||
'Drupal:updates': | ||
{ severity: normal, | ||
parameters: { | ||
max_size: 1000, | ||
warning_size: 250 | ||
} | ||
} | ||
'Database:Fulltext': { severity: normal } | ||
'Database:Size': { severity: normal } | ||
# Security | ||
'Drupal-7:User1LockDown': { severity: normal } | ||
'fs:SensitivePublicFiles': | ||
{ | ||
severity: high, | ||
parameters: { | ||
extensions: 'sql, sh, php, py, bz2, gz, tar, tgz, zip' | ||
} | ||
} | ||
include: | ||
- d7_security_review |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace Drutiny\algm\Audit; | ||
|
||
use Drutiny\algm\Utils\MarkdownTableGenerator; | ||
use Drutiny\Audit; | ||
use Drutiny\Sandbox\Sandbox; | ||
use Drutiny\Annotation\Token; | ||
|
||
/** | ||
* Look for available security modules updates. | ||
* @Token( | ||
* name = "updates", | ||
* type = "array", | ||
* description = "Description of security module updates available." | ||
* ) | ||
*/ | ||
class D7SecurityModuleUpdates extends Audit { | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function audit(Sandbox $sandbox) { | ||
|
||
try { | ||
$modules = $sandbox->exec('drush pm-updatestatus --security-only --full --format=json'); | ||
} | ||
catch (Exception $e) { | ||
throw new \Exception("Drush 8 command failed"); | ||
return Audit::ERROR; | ||
} | ||
|
||
if ($modules === '') { | ||
$sandbox->setParameter('updates', 'No security modules to update.'); | ||
return Audit::SUCCESS; | ||
} | ||
|
||
$modules = json_decode($modules, TRUE); | ||
if ($modules === null) { | ||
return AUDIT::ERROR; | ||
} | ||
|
||
$results = array_map(function($module) { | ||
return([ | ||
'name' => isset($module['name']) ? $module['name'] : '', | ||
'existing_version' => isset($module['existing_version']) ? $module['existing_version'] : '', | ||
'latest_version' => isset($module['latest_version']) ? $module['latest_version'] : '', | ||
'recommended' => isset($module['recommended']) ? $module['recommended'] : '', | ||
'status_msg' => isset($module['status_msg']) ? $module['status_msg'] : '', | ||
'link' => isset($module['link']) ? $module['link'] : '', | ||
]); | ||
}, $modules); | ||
|
||
$columns = ['Name', 'Current Version', 'Recommended', 'Status', 'Link']; | ||
$rows = []; | ||
foreach ($results as $key => $m) { | ||
$rows[] = [ $m["name"], $m["existing_version"], $m["recommended"], $m['status_msg'], $m['link'] ]; | ||
} | ||
|
||
$md_table = new MarkdownTableGenerator($columns, $rows); | ||
$rendered_table_markdown = $md_table->render(); | ||
|
||
$sandbox->setParameter('updates', $rendered_table_markdown); | ||
|
||
return Audit::FAIL; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<?php | ||
|
||
namespace Drutiny\algm\Audit; | ||
|
||
use Drutiny\algm\Utils\MarkdownTableGenerator; | ||
use Drutiny\Audit; | ||
use Drutiny\Sandbox\Sandbox; | ||
use Drutiny\Annotation\Token; | ||
use Exception; | ||
|
||
/** | ||
* Look for available security modules updates for Drupal 8. | ||
* @Token( | ||
* name = "updates", | ||
* type = "array", | ||
* description = "Description of security module updates available." | ||
* ) | ||
*/ | ||
class D8SecurityModuleUpdates extends Audit { | ||
|
||
public function getDrushVersion($sandbox) { | ||
$drush_version = trim($sandbox->exec('drush version | grep "Drush" | sed -ne \'s/[^0-9]*\(\([0-9]\.\)\{0,4\}[0-9][^.]\).*/\1/p\'')); | ||
|
||
if ($drush_version === '') { | ||
return Audit::ERROR; | ||
} | ||
|
||
return $drush_version; | ||
} | ||
|
||
public function isDrush8($drush_version) { | ||
return substr($drush_version, 0, 1 ) === "8"; | ||
} | ||
|
||
public function isDrush9($drush_version) { | ||
return substr($drush_version, 0, 1 ) === "9"; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function audit(Sandbox $sandbox) { | ||
|
||
// Detect Drush version | ||
$drush_version = $this->getDrushVersion($sandbox); | ||
$modules = []; | ||
|
||
|
||
if ($this->isDrush8($drush_version)) { | ||
try { | ||
$modules = $sandbox->exec('drush pm-updatestatus --security-only --full --format=json'); | ||
|
||
if ($modules === '') { | ||
$sandbox->setParameter('updates', 'No security modules to update.'); | ||
return Audit::SUCCESS; | ||
} | ||
} | ||
catch (Exception $e) { | ||
throw new \Exception("Drush 8 command failed"); | ||
return Audit::ERROR; | ||
} | ||
} | ||
|
||
if ($this->isDrush9($drush_version)) { | ||
try { | ||
$modules = $sandbox->exec('drush pm:security --format=json 2> /dev/null | cat $1'); | ||
} | ||
catch (Exception $e) { | ||
throw new \Exception("Drush 9 command failed"); | ||
return Audit::ERROR; | ||
} | ||
} | ||
|
||
if ($modules === '') { | ||
$sandbox->setParameter('updates', 'No security modules to update.'); | ||
return Audit::SUCCESS; | ||
} | ||
|
||
$modules = json_decode($modules, TRUE); | ||
if ($modules === null) { | ||
return AUDIT::ERROR; | ||
} | ||
|
||
if (substr($drush_version, 0, 1 ) === "8") { | ||
$results = array_map(function($module) { | ||
return([ | ||
'name' => isset($module['name']) ? $module['name'] : '', | ||
'existing_version' => isset($module['existing_version']) ? $module['existing_version'] : '', | ||
'latest_version' => isset($module['latest_version']) ? $module['latest_version'] : '', | ||
'recommended' => isset($module['recommended']) ? $module['recommended'] : '', | ||
'status_msg' => isset($module['status_msg']) ? $module['status_msg'] : '', | ||
'link' => isset($module['link']) ? $module['link'] : '', | ||
]); | ||
}, $modules); | ||
|
||
$columns = ['Name', 'Current Version', 'Recommended', 'Status', 'Link']; | ||
$rows = []; | ||
foreach ($results as $key => $m) { | ||
$rows[] = [ $m["name"], $m["existing_version"], $m["recommended"], $m['status_msg'], $m['link'] ]; | ||
} | ||
} | ||
|
||
if (substr($drush_version, 0, 1 ) === "9") { | ||
$results = array_map(function($module) { | ||
return([ | ||
'name' => isset($module['name']) ? $module['name'] : '', | ||
'version' => isset($module['version']) ? $module['version'] : '', | ||
]); | ||
}, $modules); | ||
|
||
$columns = ['Name', 'Current Version']; | ||
$rows = []; | ||
foreach ($results as $key => $m) { | ||
$rows[] = [ $m["name"], $m["version"] ]; | ||
} | ||
} | ||
|
||
$md_table = new MarkdownTableGenerator($columns, $rows); | ||
$rendered_table_markdown = $md_table->render(); | ||
|
||
$sandbox->setParameter('updates', $rendered_table_markdown); | ||
|
||
return Audit::FAIL; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.