@aaa-sentinel/iac-cost 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -10
- package/dist/cli.js +291 -43
- package/package.json +43 -43
package/README.md
CHANGED
|
@@ -7,6 +7,16 @@ internet is caught in review instead of after the deploy. With `iac-cost fix`, t
|
|
|
7
7
|
your last scan on resources this Terraform manages come back to you as **pull requests**, not as
|
|
8
8
|
console changes (see [Fixes as pull requests](#fixes-as-pull-requests)).
|
|
9
9
|
|
|
10
|
+
> **New in 0.7.0:** the plan check flags RDS and Aurora instances with `auto_minor_version_upgrade = false`
|
|
11
|
+
> (CIS AWS 2.3.2; RDS Custom is skipped), and `iac-cost fix` turns it back on. Security findings have a
|
|
12
|
+
> seventh category, `security_patching`.
|
|
13
|
+
|
|
14
|
+
> **Changed in 0.6.1:** `fix` says when the risk and compliance add-on is not active on the account, names the
|
|
15
|
+
> fixes whose pull or merge request was closed without merging (they are not reopened), and says
|
|
16
|
+
> "merge request" on GitLab. The fix jobs below no longer end in `|| true` or `continue-on-error`, so a
|
|
17
|
+
> setup error (exit code 2) fails the job instead of passing unseen. Rejected OAuth app credentials
|
|
18
|
+
> (401) or an app without the `security:fix` scope (403) are now setup errors too: exit code 2.
|
|
19
|
+
|
|
10
20
|
> **New in 0.6.0:** GitLab CI, on gitlab.com and self-managed GitLab. The `comment` subcommand posts
|
|
11
21
|
> the output as a note on the merge request and updates it on later pushes (see [GitLab CI](#gitlab-ci)),
|
|
12
22
|
> and `fix` opens merge requests (see [GitLab CI](#gitlab-ci-1) under fixes). Nothing changes on GitHub
|
|
@@ -50,7 +60,7 @@ console changes (see [Fixes as pull requests](#fixes-as-pull-requests)).
|
|
|
50
60
|
estimate needs a **Pro** or **Business** plan.
|
|
51
61
|
- For the optional **drift check**, a second application with `security:read` and the security
|
|
52
62
|
add-on on the account (see [Drift](#drift-plan-vs-cloud)).
|
|
53
|
-
- For **`iac-cost fix`**, an application with the `security:fix` scope, the
|
|
63
|
+
- For **`iac-cost fix`**, an application with the `security:fix` scope, the risk and compliance add-on on the
|
|
54
64
|
account, and a CI token that can push a branch and open a pull request (see
|
|
55
65
|
[Fixes as pull requests](#fixes-as-pull-requests)).
|
|
56
66
|
- On **GitLab**, a project access token of your own for the note or the merge request: the job
|
|
@@ -293,7 +303,7 @@ or an RDS instance is only matched when the region of the plan resource is known
|
|
|
293
303
|
their names are unique only within a region.
|
|
294
304
|
|
|
295
305
|
It needs a **separate** OAuth2 application with the `security:read` scope, in
|
|
296
|
-
`IAC_SECURITY_CLIENT_ID` / `IAC_SECURITY_CLIENT_SECRET`, and the
|
|
306
|
+
`IAC_SECURITY_CLIENT_ID` / `IAC_SECURITY_CLIENT_SECRET`, and the risk and compliance add-on on that account.
|
|
297
307
|
Keep `iac:estimate` and `security:read` in two applications: the first one is safe in a CI that
|
|
298
308
|
third parties can trigger, the second one reads your findings.
|
|
299
309
|
|
|
@@ -569,9 +579,16 @@ review its `terraform plan` before merging. The finding closes after `terraform
|
|
|
569
579
|
| `--allow-public-repo` | Opens pull requests on a public repository too |
|
|
570
580
|
| `--format <text\|json>` | Output format |
|
|
571
581
|
|
|
572
|
-
Exit code: `2` for a
|
|
573
|
-
|
|
574
|
-
|
|
582
|
+
Exit code: `2` for a setup error (no account, no git host or token, the run is a pull request build,
|
|
583
|
+
on GitLab a branch that is not protected, the input is not a plan; `IAC_FIX_CLIENT_ID` or
|
|
584
|
+
`IAC_FIX_CLIENT_SECRET` missing or rejected (401); an app without the `security:fix` scope or not allowed
|
|
585
|
+
on the account (403)); otherwise `0`, also when there is nothing to fix, when the security add-on is not
|
|
586
|
+
active on the account (402), and when the API is down (5xx), the network fails or the git host fails —
|
|
587
|
+
the step prints a warning and the findings stay `pending`. That is why the
|
|
588
|
+
jobs below do not end in `|| true` (or `continue-on-error` on GitHub): a `2` needs someone to fix the
|
|
589
|
+
pipeline and must show as a failed job, while an outage on our side never fails it. Run fixes in their
|
|
590
|
+
own workflow or job; if the job shares a GitLab pipeline with your deploy, add `allow_failure: true` to
|
|
591
|
+
it so a setup error shows as a warning without holding the later stages.
|
|
575
592
|
|
|
576
593
|
### GitHub Actions
|
|
577
594
|
|
|
@@ -606,7 +623,6 @@ jobs:
|
|
|
606
623
|
- run: terraform plan -out=plan.tfplan
|
|
607
624
|
- run: terraform show -json plan.tfplan > plan.json
|
|
608
625
|
- name: Open security fixes as pull requests
|
|
609
|
-
continue-on-error: true
|
|
610
626
|
env:
|
|
611
627
|
GITHUB_TOKEN: ${{ github.token }}
|
|
612
628
|
IAC_FIX_CLIENT_ID: ${{ secrets.IAC_FIX_CLIENT_ID }}
|
|
@@ -632,7 +648,7 @@ pipelines:
|
|
|
632
648
|
- terraform init
|
|
633
649
|
- terraform plan -out=plan.tfplan
|
|
634
650
|
- terraform show -json plan.tfplan > plan.json
|
|
635
|
-
- npx --yes @aaa-sentinel/iac-cost fix plan.json --account "$AAA_SENTINEL_ACCOUNT_ID"
|
|
651
|
+
- npx --yes @aaa-sentinel/iac-cost fix plan.json --account "$AAA_SENTINEL_ACCOUNT_ID"
|
|
636
652
|
```
|
|
637
653
|
|
|
638
654
|
The commit is created through the Bitbucket API (`POST /src`), so the clone needs no push access.
|
|
@@ -660,15 +676,16 @@ security-fixes:
|
|
|
660
676
|
- terraform plan -out=plan.tfplan
|
|
661
677
|
- terraform show -json plan.tfplan > plan.json
|
|
662
678
|
# GITLAB_FIX_TOKEN (Developer, api), IAC_FIX_CLIENT_ID and IAC_FIX_CLIENT_SECRET: masked, protected variables.
|
|
663
|
-
- npx --yes @aaa-sentinel/iac-cost fix plan.json --account "$AAA_SENTINEL_ACCOUNT_ID"
|
|
679
|
+
- npx --yes @aaa-sentinel/iac-cost fix plan.json --account "$AAA_SENTINEL_ACCOUNT_ID"
|
|
664
680
|
```
|
|
665
681
|
|
|
666
682
|
The branch and the commit are created in one call to the GitLab API (`POST /repository/commits` from
|
|
667
683
|
the deployed commit), so the clone needs no push access. A project with **internal** visibility counts
|
|
668
684
|
as public (every user of the server, or of gitlab.com, can read it): pass `--allow-public-repo` if
|
|
669
685
|
that is acceptable. It refuses to run on a merge request or tag pipeline, and on a branch that is not
|
|
670
|
-
protected (`CI_COMMIT_REF_PROTECTED` is not `true`)
|
|
671
|
-
variable, so an unprotected branch means the setup is wrong.
|
|
686
|
+
protected (`CI_COMMIT_REF_PROTECTED` is not `true`) with exit code `2`, so the job fails: the token
|
|
687
|
+
that can push lives in a protected variable, so an unprotected branch means the setup is wrong.
|
|
688
|
+
Protect the branch you deploy.
|
|
672
689
|
|
|
673
690
|
## Posture over time
|
|
674
691
|
|
package/dist/cli.js
CHANGED
|
@@ -6711,6 +6711,21 @@ function aggregateEstimates(estimates) {
|
|
|
6711
6711
|
catalogs: [...catalogs.values()]
|
|
6712
6712
|
};
|
|
6713
6713
|
}
|
|
6714
|
+
var TokenHttpError = class extends Error {
|
|
6715
|
+
constructor(status, code2) {
|
|
6716
|
+
super(`iac_cost_token_http_${status}`);
|
|
6717
|
+
this.status = status;
|
|
6718
|
+
this.code = code2;
|
|
6719
|
+
}
|
|
6720
|
+
};
|
|
6721
|
+
async function apiErrorCode(response) {
|
|
6722
|
+
try {
|
|
6723
|
+
const body2 = await response.json();
|
|
6724
|
+
return typeof body2.code === "string" && /^[A-Z][A-Z0-9_]{0,63}$/.test(body2.code) ? body2.code : null;
|
|
6725
|
+
} catch {
|
|
6726
|
+
return null;
|
|
6727
|
+
}
|
|
6728
|
+
}
|
|
6714
6729
|
async function fetchToken(config2, scope = TOKEN_SCOPE) {
|
|
6715
6730
|
const fetchImpl = config2.fetchImpl ?? fetch;
|
|
6716
6731
|
const response = await fetchImpl(`${config2.baseUrl}/v1/oauth/token`, {
|
|
@@ -6724,7 +6739,7 @@ async function fetchToken(config2, scope = TOKEN_SCOPE) {
|
|
|
6724
6739
|
scope
|
|
6725
6740
|
})
|
|
6726
6741
|
});
|
|
6727
|
-
if (!response.ok) throw new
|
|
6742
|
+
if (!response.ok) throw new TokenHttpError(response.status, await apiErrorCode(response));
|
|
6728
6743
|
const body2 = await response.json();
|
|
6729
6744
|
if (typeof body2.access_token !== "string") throw new Error("iac_cost_token_missing");
|
|
6730
6745
|
return body2.access_token;
|
|
@@ -6791,18 +6806,31 @@ import { parseArgs as parseArgs3 } from "node:util";
|
|
|
6791
6806
|
// src/fix/api.ts
|
|
6792
6807
|
var SCOPE = "security:fix";
|
|
6793
6808
|
var TIMEOUT_MS2 = 35e3;
|
|
6809
|
+
var CodeFixApiError = class extends Error {
|
|
6810
|
+
constructor(status, code2, stage = "findings") {
|
|
6811
|
+
super(`${stage === "token" ? "iac_cost_token_http_" : "code_fixes_http_"}${status}${code2 ? ` ${code2}` : ""}`);
|
|
6812
|
+
this.status = status;
|
|
6813
|
+
this.code = code2;
|
|
6814
|
+
this.stage = stage;
|
|
6815
|
+
}
|
|
6816
|
+
};
|
|
6794
6817
|
function codeFixApi(config2) {
|
|
6795
6818
|
const fetchImpl = config2.fetchImpl ?? fetch;
|
|
6796
6819
|
const url = `${config2.baseUrl}/v1/security/code-fixes?accountId=${encodeURIComponent(config2.accountId)}`;
|
|
6797
6820
|
let token = null;
|
|
6798
6821
|
const bearer = async () => {
|
|
6799
|
-
|
|
6822
|
+
try {
|
|
6823
|
+
token ??= await fetchToken(config2, SCOPE);
|
|
6824
|
+
} catch (error2) {
|
|
6825
|
+
if (error2 instanceof TokenHttpError) throw new CodeFixApiError(error2.status, error2.code, "token");
|
|
6826
|
+
throw error2;
|
|
6827
|
+
}
|
|
6800
6828
|
return token;
|
|
6801
6829
|
};
|
|
6802
6830
|
return {
|
|
6803
6831
|
async load() {
|
|
6804
6832
|
const response = await fetchImpl(url, { headers: { authorization: `Bearer ${await bearer()}` }, signal: AbortSignal.timeout(TIMEOUT_MS2) });
|
|
6805
|
-
if (!response.ok) throw new
|
|
6833
|
+
if (!response.ok) throw new CodeFixApiError(response.status, await apiErrorCode(response));
|
|
6806
6834
|
const body2 = await response.json();
|
|
6807
6835
|
const findings = (body2.findings ?? []).flatMap(
|
|
6808
6836
|
(f) => typeof f.findingId === "string" && typeof f.ruleId === "string" && typeof f.resourceId === "string" ? [{
|
|
@@ -8142,6 +8170,7 @@ function rdsInstances(index) {
|
|
|
8142
8170
|
const builder = new ObservationBuilder(index, db, "rds_instance", "aws").cloudId("identifier");
|
|
8143
8171
|
builder.from("engine", index.get(db, "engine"), String, null);
|
|
8144
8172
|
builder.from("publiclyAccessible", index.get(db, "publicly_accessible"), Boolean, false);
|
|
8173
|
+
builder.from("autoMinorVersionUpgrade", index.get(db, "auto_minor_version_upgrade"), Boolean, true);
|
|
8145
8174
|
if (db.type === "aws_rds_cluster_instance") {
|
|
8146
8175
|
const cluster = index.parentOf(db, "cluster_identifier", ["aws_rds_cluster"], "cluster_identifier");
|
|
8147
8176
|
const clusterId = index.get(db, "cluster_identifier");
|
|
@@ -8629,6 +8658,7 @@ var RULE_TITLES = {
|
|
|
8629
8658
|
SEC_AWS_IAM_POLITICA_CONTRASENAS: "Weak or missing IAM password policy",
|
|
8630
8659
|
SEC_AWS_ENCRYPTION_KMS_SIN_ROTACION: "KMS key without rotation",
|
|
8631
8660
|
SEC_AWS_ENCRYPTION_RDS_SIN_CIFRAR: "Unencrypted RDS",
|
|
8661
|
+
SEC_AWS_PATCHING_RDS_SIN_ACTUALIZACION_MENOR: "RDS without automatic minor version upgrade",
|
|
8632
8662
|
SEC_AWS_LOGGING_TRAIL_PARADO: "CloudTrail stopped",
|
|
8633
8663
|
SEC_AWS_LOGGING_TRAIL_GESTION_INCOMPLETA: "CloudTrail skips some management events",
|
|
8634
8664
|
SEC_AWS_LOGGING_VPC_SIN_FLOW_LOGS: "VPC without flow logs",
|
|
@@ -8976,6 +9006,14 @@ function kmsRotation(ctx, builder) {
|
|
|
8976
9006
|
throw new FixedInCode(where.file, "enable_key_rotation");
|
|
8977
9007
|
}
|
|
8978
9008
|
}
|
|
9009
|
+
function rdsAutoMinor(ctx, builder) {
|
|
9010
|
+
const where = located(ctx, ctx.anchor);
|
|
9011
|
+
const items = body(where.text, where.block);
|
|
9012
|
+
if (setLiteral(builder, where, items, "auto_minor_version_upgrade", "true", (l) => l?.kind === "bool" && l.value) === "already") {
|
|
9013
|
+
throw new FixedInCode(where.file, "auto_minor_version_upgrade");
|
|
9014
|
+
}
|
|
9015
|
+
builder.changes.push("note: RDS may apply a pending minor version upgrade in the next maintenance window, which restarts the instance");
|
|
9016
|
+
}
|
|
8979
9017
|
function lambdaUrl(ctx, builder) {
|
|
8980
9018
|
const { index, anchor: anchor2 } = ctx;
|
|
8981
9019
|
const urls = index.ofType("aws_lambda_function_url").filter((url) => index.parentOf(url, "function_name", ["aws_lambda_function"], "function_name", lambdaName) === anchor2).filter((url) => {
|
|
@@ -9030,6 +9068,7 @@ var FIXERS = {
|
|
|
9030
9068
|
SEC_AWS_NETWORK_ADMIN_ABIERTO: { types: ["aws_security_group", "aws_default_security_group"], fix: awsAdminOpen },
|
|
9031
9069
|
SEC_AWS_EXPOSURE_S3_PUBLICO: { types: ["aws_s3_bucket"], fix: s3PublicAccess },
|
|
9032
9070
|
SEC_AWS_ENCRYPTION_KMS_SIN_ROTACION: { types: ["aws_kms_key"], fix: kmsRotation },
|
|
9071
|
+
SEC_AWS_PATCHING_RDS_SIN_ACTUALIZACION_MENOR: { types: ["aws_db_instance", "aws_rds_cluster_instance"], fix: rdsAutoMinor },
|
|
9033
9072
|
SEC_AWS_EXPOSURE_LAMBDA_PUBLICA: { types: ["aws_lambda_function"], fix: lambdaUrl },
|
|
9034
9073
|
SEC_AZURE_EXPOSURE_BLOB_PUBLICO: { types: ["azurerm_storage_account"], fix: azureBlobPublic },
|
|
9035
9074
|
SEC_AZURE_ENCRYPTION_STORAGE_TLS: { types: ["azurerm_storage_account"], fix: azureStorageTls },
|
|
@@ -9088,7 +9127,7 @@ function title(ruleId) {
|
|
|
9088
9127
|
function pullRequestTitle(ruleId, address) {
|
|
9089
9128
|
return `fix(security): ${title(ruleId)} on ${address}`.slice(0, 250);
|
|
9090
9129
|
}
|
|
9091
|
-
function pullRequestBody(finding, outcome, accountId) {
|
|
9130
|
+
function pullRequestBody(finding, outcome, accountId, kind = "pull request") {
|
|
9092
9131
|
return [
|
|
9093
9132
|
`<!-- aaa-sentinel:code-fix ${finding.findingId} -->`,
|
|
9094
9133
|
"### \u{1F512} Security fix from AAA Sentinel",
|
|
@@ -9102,7 +9141,7 @@ function pullRequestBody(finding, outcome, accountId) {
|
|
|
9102
9141
|
`Files: ${outcome.patches.map((patch) => `\`${patch.file}\``).join(", ")}`,
|
|
9103
9142
|
"",
|
|
9104
9143
|
"Only literal values in the resource block were edited. Review the `terraform plan` of this branch before merging;",
|
|
9105
|
-
|
|
9144
|
+
`the finding closes after \`terraform apply\` and the next scan. Close this ${kind} to decline the fix.`
|
|
9106
9145
|
].join("\n");
|
|
9107
9146
|
}
|
|
9108
9147
|
function allObservations(index) {
|
|
@@ -9131,6 +9170,31 @@ function anchorFor(index, observations, finding, input) {
|
|
|
9131
9170
|
const scope = cloudScopeOf(resource);
|
|
9132
9171
|
return scope === null || scope.toLowerCase() === input.cloudAccountId.toLowerCase() ? resource : null;
|
|
9133
9172
|
}
|
|
9173
|
+
function loadFailure(error2, accountId) {
|
|
9174
|
+
if (!(error2 instanceof CodeFixApiError)) return { message: `could not read the open findings, nothing to fix: ${error2.message}`, setup: false };
|
|
9175
|
+
const { status, code: code2, stage } = error2;
|
|
9176
|
+
const tag = `${status}${code2 ? ` ${code2}` : ""}`;
|
|
9177
|
+
if (stage === "token" && status === 401) {
|
|
9178
|
+
return { message: `AAA Sentinel rejected the OAuth app credentials (${tag}): check IAC_FIX_CLIENT_ID and IAC_FIX_CLIENT_SECRET`, setup: true };
|
|
9179
|
+
}
|
|
9180
|
+
if (stage === "token" && code2 === "INVALID_SCOPE") {
|
|
9181
|
+
return { message: `the OAuth app in IAC_FIX_CLIENT_ID does not have the security:fix scope (${tag}): create an app with that scope`, setup: true };
|
|
9182
|
+
}
|
|
9183
|
+
if (stage === "findings" && status === 401) {
|
|
9184
|
+
return { message: `AAA Sentinel rejected the access token of the OAuth app (${tag}): check IAC_FIX_CLIENT_ID and IAC_FIX_CLIENT_SECRET`, setup: true };
|
|
9185
|
+
}
|
|
9186
|
+
if (stage === "findings" && status === 403) {
|
|
9187
|
+
const detail = code2 === "INSUFFICIENT_SCOPE" ? "the OAuth app in IAC_FIX_CLIENT_ID does not have the security:fix scope: create an app with that scope" : `the OAuth app in IAC_FIX_CLIENT_ID cannot use account ${accountId}: check --account and the accounts the app is limited to`;
|
|
9188
|
+
return { message: `${detail} (${tag})`, setup: true };
|
|
9189
|
+
}
|
|
9190
|
+
if (code2 === "SECURITY_ADDON_INACTIVE") {
|
|
9191
|
+
return { message: `the risk and compliance add-on is not active on account ${accountId} (402 SECURITY_ADDON_INACTIVE): activate it in AAA Sentinel to get fixes; nothing to fix`, setup: false };
|
|
9192
|
+
}
|
|
9193
|
+
if (code2 === "PLAN_SECURITY_ADDON") {
|
|
9194
|
+
return { message: `the plan of this organization does not include the risk and compliance add-on (402 PLAN_SECURITY_ADDON): fixes need the Pro or Business plan with the add-on; nothing to fix`, setup: false };
|
|
9195
|
+
}
|
|
9196
|
+
return { message: `could not read the open findings, nothing to fix: ${error2.message}`, setup: false };
|
|
9197
|
+
}
|
|
9134
9198
|
function prState(state) {
|
|
9135
9199
|
return state === "open" ? "pr_open" : state;
|
|
9136
9200
|
}
|
|
@@ -9141,14 +9205,20 @@ function carry(findingId, fix2, state) {
|
|
|
9141
9205
|
async function runFix(options, deps) {
|
|
9142
9206
|
const warnings = [];
|
|
9143
9207
|
const lines2 = [];
|
|
9208
|
+
const declined = [];
|
|
9144
9209
|
const reports = [];
|
|
9145
9210
|
const { host } = deps;
|
|
9211
|
+
const mr = host?.kind === "gitlab";
|
|
9212
|
+
const kind = mr ? "merge request" : "pull request";
|
|
9213
|
+
const ref = (n) => mr ? `!${n}` : `#${n}`;
|
|
9214
|
+
const hostTag = host ? { host: host.kind } : {};
|
|
9146
9215
|
let input;
|
|
9147
9216
|
try {
|
|
9148
9217
|
input = await deps.api.load();
|
|
9149
9218
|
} catch (error2) {
|
|
9150
|
-
|
|
9151
|
-
|
|
9219
|
+
const failure2 = loadFailure(error2, deps.accountId);
|
|
9220
|
+
warnings.push(failure2.message);
|
|
9221
|
+
return { stdout: render(options, { lines: lines2, declined, mr }, deps.accountId, null), warnings, lines: lines2, declined, reported: 0, setupError: failure2.setup };
|
|
9152
9222
|
}
|
|
9153
9223
|
if (input.truncated) warnings.push("the account has more open findings than the API returns (500 most severe): the rest are left for a later run");
|
|
9154
9224
|
let publicRepo = false;
|
|
@@ -9158,9 +9228,9 @@ async function runFix(options, deps) {
|
|
|
9158
9228
|
publicRepo = !await host.isPrivate();
|
|
9159
9229
|
} catch (error2) {
|
|
9160
9230
|
publicRepo = true;
|
|
9161
|
-
warnings.push(`could not tell whether the repository is private, no
|
|
9231
|
+
warnings.push(`could not tell whether the repository is private, no ${kind} opened: ${error2.message}`);
|
|
9162
9232
|
}
|
|
9163
|
-
if (publicRepo) warnings.push(
|
|
9233
|
+
if (publicRepo) warnings.push(`the repository is public: no ${kind} opened (pass --allow-public-repo to open them anyway)`);
|
|
9164
9234
|
}
|
|
9165
9235
|
const index = new PlanIndex(deps.plan);
|
|
9166
9236
|
const observations = allObservations(index);
|
|
@@ -9169,13 +9239,18 @@ async function runFix(options, deps) {
|
|
|
9169
9239
|
const existing = input.fixes.get(finding.findingId);
|
|
9170
9240
|
const sameRepo = Boolean(existing && host && existing.host === host.kind && existing.repository === host.repository && existing.server === host.server);
|
|
9171
9241
|
if (existing && CODE_FIX_PR_STATES.includes(existing.state) && !sameRepo) continue;
|
|
9172
|
-
if (existing?.state === "closed")
|
|
9242
|
+
if (existing?.state === "closed") {
|
|
9243
|
+
if (anchorFor(index, observations, finding, input)) {
|
|
9244
|
+
declined.push({ findingId: finding.findingId, ruleId: finding.ruleId, address: existing.address, ...existing.pullRequest ? { pullRequest: existing.pullRequest.url } : {} });
|
|
9245
|
+
}
|
|
9246
|
+
continue;
|
|
9247
|
+
}
|
|
9173
9248
|
if (existing && host && sameRepo && existing.state === "pr_open" && existing.pullRequest) {
|
|
9174
9249
|
let state = "pr_open";
|
|
9175
9250
|
try {
|
|
9176
9251
|
state = prState(await host.pullRequestState(existing.pullRequest.number));
|
|
9177
9252
|
} catch (error2) {
|
|
9178
|
-
warnings.push(`could not read
|
|
9253
|
+
warnings.push(`could not read ${kind} ${ref(existing.pullRequest.number)}: ${error2.message}`);
|
|
9179
9254
|
}
|
|
9180
9255
|
if (state !== "merged") {
|
|
9181
9256
|
reports.push(carry(finding.findingId, existing, state));
|
|
@@ -9212,19 +9287,20 @@ async function runFix(options, deps) {
|
|
|
9212
9287
|
reason: outcome.reason,
|
|
9213
9288
|
address: outcome.address,
|
|
9214
9289
|
...outcome.file !== void 0 ? { file: outcome.file } : {},
|
|
9215
|
-
...outcome.attribute !== void 0 ? { attribute: outcome.attribute } : {}
|
|
9290
|
+
...outcome.attribute !== void 0 ? { attribute: outcome.attribute } : {},
|
|
9291
|
+
...hostTag
|
|
9216
9292
|
});
|
|
9217
9293
|
lines2.push({ ...base, outcome: "suggested", reason: outcome.reason, ...outcome.file !== void 0 ? { file: outcome.file } : {} });
|
|
9218
9294
|
continue;
|
|
9219
9295
|
}
|
|
9220
9296
|
if (outcome.kind === "fixed_in_code") {
|
|
9221
|
-
reports.push({ findingId: finding.findingId, state: "pending", reason: "fixed_in_code", address: outcome.address, file: outcome.file, attribute: outcome.attribute });
|
|
9297
|
+
reports.push({ findingId: finding.findingId, state: "pending", reason: "fixed_in_code", address: outcome.address, file: outcome.file, attribute: outcome.attribute, ...hostTag });
|
|
9222
9298
|
lines2.push({ ...base, outcome: "pending", reason: "fixed_in_code", file: outcome.file });
|
|
9223
9299
|
continue;
|
|
9224
9300
|
}
|
|
9225
9301
|
const patch = outcome;
|
|
9226
9302
|
const pending = (reason) => {
|
|
9227
|
-
reports.push({ findingId: finding.findingId, state: "pending", reason, address: patch.address, file: patch.file, attribute: patch.attribute });
|
|
9303
|
+
reports.push({ findingId: finding.findingId, state: "pending", reason, address: patch.address, file: patch.file, attribute: patch.attribute, ...hostTag });
|
|
9228
9304
|
lines2.push({ ...base, outcome: "pending", reason, file: patch.file, changes: patch.changes });
|
|
9229
9305
|
};
|
|
9230
9306
|
if (options.dryRun || !host) {
|
|
@@ -9232,7 +9308,7 @@ async function runFix(options, deps) {
|
|
|
9232
9308
|
continue;
|
|
9233
9309
|
}
|
|
9234
9310
|
if (host.unsupported) {
|
|
9235
|
-
reports.push({ findingId: finding.findingId, state: "suggested", reason: "unsupported_host", address: patch.address, file: patch.file, attribute: patch.attribute });
|
|
9311
|
+
reports.push({ findingId: finding.findingId, state: "suggested", reason: "unsupported_host", address: patch.address, file: patch.file, attribute: patch.attribute, ...hostTag });
|
|
9236
9312
|
lines2.push({ ...base, outcome: "suggested", reason: "unsupported_host", file: patch.file, changes: patch.changes });
|
|
9237
9313
|
continue;
|
|
9238
9314
|
}
|
|
@@ -9267,7 +9343,7 @@ async function runFix(options, deps) {
|
|
|
9267
9343
|
record2(pr2, prState(pr2.state));
|
|
9268
9344
|
continue;
|
|
9269
9345
|
}
|
|
9270
|
-
const reopened = await host.openPullRequest(branch, title2, pullRequestBody(finding, patch, deps.accountId));
|
|
9346
|
+
const reopened = await host.openPullRequest(branch, title2, pullRequestBody(finding, patch, deps.accountId, kind));
|
|
9271
9347
|
opened += 1;
|
|
9272
9348
|
record2(reopened, "pr_open");
|
|
9273
9349
|
continue;
|
|
@@ -9287,12 +9363,12 @@ async function runFix(options, deps) {
|
|
|
9287
9363
|
return { path: file.file, content: atBase === file.original ? patched : likeBase(patched, atBase) };
|
|
9288
9364
|
});
|
|
9289
9365
|
await host.createBranchWithCommit(branch, title2, files);
|
|
9290
|
-
const pr = await host.openPullRequest(branch, title2, pullRequestBody(finding, patch, deps.accountId));
|
|
9366
|
+
const pr = await host.openPullRequest(branch, title2, pullRequestBody(finding, patch, deps.accountId, kind));
|
|
9291
9367
|
opened += 1;
|
|
9292
9368
|
record2(pr, "pr_open");
|
|
9293
9369
|
} catch (error2) {
|
|
9294
9370
|
if (error2 instanceof SkipFinding) continue;
|
|
9295
|
-
warnings.push(`could not open the
|
|
9371
|
+
warnings.push(`could not open the ${kind} for ${patch.address}: ${error2.message}`);
|
|
9296
9372
|
pending("pr_failed");
|
|
9297
9373
|
}
|
|
9298
9374
|
}
|
|
@@ -9303,12 +9379,12 @@ async function runFix(options, deps) {
|
|
|
9303
9379
|
reported = result.accepted;
|
|
9304
9380
|
if (result.notFound > 0) warnings.push(`${result.notFound} fixes were not recorded: their findings are no longer open`);
|
|
9305
9381
|
if (result.duplicates > 0) warnings.push(`${result.duplicates} fixes were not recorded: the same finding was reported twice in one run`);
|
|
9306
|
-
if (result.stale > 0) warnings.push(`${result.stale} fixes were not recorded: AAA Sentinel already has a newer
|
|
9382
|
+
if (result.stale > 0) warnings.push(`${result.stale} fixes were not recorded: AAA Sentinel already has a newer ${kind} state for them`);
|
|
9307
9383
|
} catch (error2) {
|
|
9308
9384
|
warnings.push(`could not record the fixes in AAA Sentinel: ${error2.message}`);
|
|
9309
9385
|
}
|
|
9310
9386
|
}
|
|
9311
|
-
return { stdout: render(options, lines2, deps.accountId, input.scanAt), warnings, lines: lines2, reported };
|
|
9387
|
+
return { stdout: render(options, { lines: lines2, declined, mr }, deps.accountId, input.scanAt), warnings, lines: lines2, declined, reported, setupError: false };
|
|
9312
9388
|
}
|
|
9313
9389
|
var SkipFinding = class extends Error {
|
|
9314
9390
|
};
|
|
@@ -9327,15 +9403,23 @@ var OUTCOME_TEXT = {
|
|
|
9327
9403
|
pending: "pending",
|
|
9328
9404
|
suggested: "change suggested, no pull request"
|
|
9329
9405
|
};
|
|
9330
|
-
function render(options, lines2, accountId, scanAt) {
|
|
9331
|
-
if (options.format === "json") return JSON.stringify({ formatVersion: "1", accountId, scanAt, dryRun: options.dryRun, fixes: lines2 }, null, 2);
|
|
9332
|
-
|
|
9333
|
-
const out = [
|
|
9406
|
+
function render(options, { lines: lines2, declined, mr }, accountId, scanAt) {
|
|
9407
|
+
if (options.format === "json") return JSON.stringify({ formatVersion: "1", accountId, scanAt, dryRun: options.dryRun, fixes: lines2, declined }, null, 2);
|
|
9408
|
+
const kind = mr ? "merge request" : "pull request";
|
|
9409
|
+
const out = [];
|
|
9410
|
+
if (lines2.length === 0 && declined.length === 0) return `No open finding of account ${accountId} matches a resource of this plan.`;
|
|
9411
|
+
const dryRun = options.dryRun ? " (dry run: nothing opened or recorded)" : "";
|
|
9412
|
+
if (lines2.length === 0) out.push(`No new fix for account ${accountId}${dryRun}.`);
|
|
9413
|
+
else out.push(`Security fixes for account ${accountId}${dryRun}`);
|
|
9334
9414
|
for (const line of lines2) {
|
|
9335
9415
|
const detail = [line.reason, line.file, line.pullRequest].filter(Boolean).join(", ");
|
|
9336
|
-
out.push(` ${line.address} \u2014 ${title(line.ruleId)}: ${OUTCOME_TEXT[line.outcome]}${detail ? ` (${detail})` : ""}`);
|
|
9416
|
+
out.push(` ${line.address} \u2014 ${title(line.ruleId)}: ${OUTCOME_TEXT[line.outcome].replace("pull request", kind)}${detail ? ` (${detail})` : ""}`);
|
|
9337
9417
|
for (const change of line.changes ?? []) out.push(` ${change}`);
|
|
9338
9418
|
}
|
|
9419
|
+
if (declined.length > 0) {
|
|
9420
|
+
out.push(`${declined.length} earlier ${declined.length === 1 ? "fix was" : "fixes were"} declined: ${declined.length === 1 ? "its" : "their"} ${kind}${declined.length === 1 ? " was" : "s were"} closed without merging and no new one is opened:`);
|
|
9421
|
+
for (const fix2 of declined) out.push(` ${fix2.findingId.slice(0, 12)} ${fix2.address} \u2014 ${title(fix2.ruleId)}${fix2.pullRequest ? `: ${fix2.pullRequest}` : ""}`);
|
|
9422
|
+
}
|
|
9339
9423
|
return out.join("\n");
|
|
9340
9424
|
}
|
|
9341
9425
|
|
|
@@ -9439,7 +9523,7 @@ ${FIX_USAGE}`);
|
|
|
9439
9523
|
}
|
|
9440
9524
|
const locator = new SourceLocator(configurationOf(plan), workDir, repoRoot ?? workDir);
|
|
9441
9525
|
const result = await runFix({ dryRun, maxPrs, format, allowPublicRepo: values["allow-public-repo"] === true }, { plan, api, host, locator, accountId: account });
|
|
9442
|
-
return { stdout: result.stdout, warnings: [...warnings, ...result.warnings], exitCode: 0 };
|
|
9526
|
+
return { stdout: result.stdout, warnings: [...warnings, ...result.warnings], exitCode: result.setupError ? 2 : 0 };
|
|
9443
9527
|
}
|
|
9444
9528
|
|
|
9445
9529
|
// src/posture/posture.ts
|
|
@@ -9596,7 +9680,7 @@ ${POSTURE_USAGE}`);
|
|
|
9596
9680
|
return { stdout: null, warnings: [...warnings, `could not read the posture history, skipping: ${mensaje}`], exitCode: 0 };
|
|
9597
9681
|
}
|
|
9598
9682
|
if (history.access !== "full") {
|
|
9599
|
-
return { stdout: null, warnings: [...warnings, "the account does not have the
|
|
9683
|
+
return { stdout: null, warnings: [...warnings, "the account does not have the risk and compliance add-on: no posture history to show"], exitCode: 0 };
|
|
9600
9684
|
}
|
|
9601
9685
|
const nuevos = gate ? newAtOrAbove(history.summary, gate) : 0;
|
|
9602
9686
|
const stdout = format === "json" ? JSON.stringify(history, null, 2) : renderPosture(history, format);
|
|
@@ -9859,6 +9943,23 @@ function costEvidence(input, signal, options) {
|
|
|
9859
9943
|
...options.amount ? { monthlySavingsUsd: signal.monthlySavingsUsd } : {}
|
|
9860
9944
|
};
|
|
9861
9945
|
}
|
|
9946
|
+
function withCostSignal(input, options) {
|
|
9947
|
+
const senales = new Map(costSignalsOf(input, options.costRule).map((s) => [options.signalKey(s), s]));
|
|
9948
|
+
if (senales.size === 0) return [];
|
|
9949
|
+
return input.findings.filter((f) => f.ruleId === options.rule).flatMap((f) => {
|
|
9950
|
+
const coste = senales.get(options.findingKey(f));
|
|
9951
|
+
if (!coste) return [];
|
|
9952
|
+
return [
|
|
9953
|
+
{
|
|
9954
|
+
region: f.region,
|
|
9955
|
+
resourceId: f.resourceId,
|
|
9956
|
+
resourceName: f.resourceName,
|
|
9957
|
+
findingIds: [f.id],
|
|
9958
|
+
evidence: costEvidence(input, coste, { amount: options.amount })
|
|
9959
|
+
}
|
|
9960
|
+
];
|
|
9961
|
+
});
|
|
9962
|
+
}
|
|
9862
9963
|
var indices = /* @__PURE__ */ new WeakMap();
|
|
9863
9964
|
function observationOf(input, kind, region, id) {
|
|
9864
9965
|
let indice = indices.get(input.observations);
|
|
@@ -9905,11 +10006,18 @@ function lambdaRef(resourceId, region) {
|
|
|
9905
10006
|
}
|
|
9906
10007
|
return `${region}::${resourceId}`;
|
|
9907
10008
|
}
|
|
10009
|
+
var LAMBDA_SIN_USO = {
|
|
10010
|
+
costRule: "SERVERLESS_UNUSED_LAMBDA",
|
|
10011
|
+
findingKey: (f) => lambdaRef(f.resourceId, f.region),
|
|
10012
|
+
signalKey: (s) => lambdaRef(s.resourceId, s.region),
|
|
10013
|
+
amount: false
|
|
10014
|
+
};
|
|
9908
10015
|
var AWS_SECURITY_COMBOS = [
|
|
9909
10016
|
{
|
|
9910
10017
|
// Cualquiera puede invocarla y lleva credenciales en su configuración: un fallo de la función las expone.
|
|
9911
10018
|
id: "COMBO_AWS_PUBLIC_FUNCTION_SECRETS",
|
|
9912
10019
|
provider: "aws",
|
|
10020
|
+
resourceKind: "lambda_function",
|
|
9913
10021
|
severity: "critical",
|
|
9914
10022
|
rules: ["SEC_AWS_EXPOSURE_LAMBDA_PUBLICA", "SEC_AWS_SECRETS_LAMBDA_ENV"],
|
|
9915
10023
|
detect: (input) => sameResource(input, "SEC_AWS_EXPOSURE_LAMBDA_PUBLICA", "SEC_AWS_SECRETS_LAMBDA_ENV")
|
|
@@ -9918,23 +10026,83 @@ var AWS_SECURITY_COMBOS = [
|
|
|
9918
10026
|
// Cualquiera puede invocarla y nadie la ha invocado en 30 días: superficie de ataque que no da servicio a nadie.
|
|
9919
10027
|
id: "COMBO_AWS_PUBLIC_FUNCTION_UNUSED",
|
|
9920
10028
|
provider: "aws",
|
|
10029
|
+
resourceKind: "lambda_function",
|
|
9921
10030
|
severity: "high",
|
|
9922
10031
|
rules: ["SEC_AWS_EXPOSURE_LAMBDA_PUBLICA"],
|
|
9923
10032
|
costRules: ["SERVERLESS_UNUSED_LAMBDA"],
|
|
10033
|
+
detect: (input) => withCostSignal(input, { rule: "SEC_AWS_EXPOSURE_LAMBDA_PUBLICA", ...LAMBDA_SIN_USO })
|
|
10034
|
+
},
|
|
10035
|
+
{
|
|
10036
|
+
// Guarda credenciales en su configuración y nadie la invoca: se borra y se rotan las credenciales.
|
|
10037
|
+
id: "COMBO_AWS_UNUSED_FUNCTION_SECRETS",
|
|
10038
|
+
provider: "aws",
|
|
10039
|
+
resourceKind: "lambda_function",
|
|
10040
|
+
severity: "high",
|
|
10041
|
+
rules: ["SEC_AWS_SECRETS_LAMBDA_ENV"],
|
|
10042
|
+
costRules: ["SERVERLESS_UNUSED_LAMBDA"],
|
|
9924
10043
|
detect: (input) => {
|
|
9925
|
-
const
|
|
9926
|
-
|
|
9927
|
-
|
|
9928
|
-
|
|
9929
|
-
if (!coste) return [];
|
|
9930
|
-
return [{ region: f.region, resourceId: f.resourceId, resourceName: f.resourceName, findingIds: [f.id], evidence: costEvidence(input, coste, { amount: false }) }];
|
|
9931
|
-
});
|
|
10044
|
+
const publicas = findingsByResource(input.findings, "SEC_AWS_EXPOSURE_LAMBDA_PUBLICA");
|
|
10045
|
+
return withCostSignal(input, { rule: "SEC_AWS_SECRETS_LAMBDA_ENV", ...LAMBDA_SIN_USO }).filter(
|
|
10046
|
+
(m) => !publicas.has(`${m.region}::${m.resourceId}`)
|
|
10047
|
+
);
|
|
9932
10048
|
}
|
|
9933
10049
|
},
|
|
10050
|
+
{
|
|
10051
|
+
// Cualquiera puede copiarlo y su volumen de origen ya no existe; se sigue pagando cada mes.
|
|
10052
|
+
id: "COMBO_AWS_PUBLIC_SNAPSHOT_ORPHAN",
|
|
10053
|
+
provider: "aws",
|
|
10054
|
+
resourceKind: "ebs_snapshot",
|
|
10055
|
+
severity: "critical",
|
|
10056
|
+
rules: ["SEC_AWS_EXPOSURE_EBS_SNAPSHOT_PUBLICO"],
|
|
10057
|
+
costRules: ["STORAGE_ORPHAN_SNAPSHOT"],
|
|
10058
|
+
detect: (input) => withCostSignal(input, {
|
|
10059
|
+
rule: "SEC_AWS_EXPOSURE_EBS_SNAPSHOT_PUBLICO",
|
|
10060
|
+
costRule: "STORAGE_ORPHAN_SNAPSHOT",
|
|
10061
|
+
// Los dos módulos usan el id del snapshot (snap-…) y la región.
|
|
10062
|
+
findingKey: (f) => `${f.region}::${f.resourceId}`,
|
|
10063
|
+
signalKey: (s) => `${s.region}::${s.resourceId}`,
|
|
10064
|
+
amount: true
|
|
10065
|
+
})
|
|
10066
|
+
},
|
|
10067
|
+
{
|
|
10068
|
+
// Endpoint público y una semana sin conexiones: se paga por una puerta abierta que nadie usa.
|
|
10069
|
+
id: "COMBO_AWS_PUBLIC_DB_IDLE",
|
|
10070
|
+
provider: "aws",
|
|
10071
|
+
resourceKind: "rds_instance",
|
|
10072
|
+
severity: "high",
|
|
10073
|
+
rules: ["SEC_AWS_EXPOSURE_RDS_PUBLICA"],
|
|
10074
|
+
costRules: ["DATABASE_ZERO_CONN_RDS"],
|
|
10075
|
+
detect: (input) => withCostSignal(input, {
|
|
10076
|
+
rule: "SEC_AWS_EXPOSURE_RDS_PUBLICA",
|
|
10077
|
+
costRule: "DATABASE_ZERO_CONN_RDS",
|
|
10078
|
+
// Los dos módulos usan el DBInstanceIdentifier, único por región.
|
|
10079
|
+
findingKey: (f) => `${f.region}::${f.resourceId}`,
|
|
10080
|
+
signalKey: (s) => `${s.region}::${s.resourceId}`,
|
|
10081
|
+
amount: true
|
|
10082
|
+
})
|
|
10083
|
+
},
|
|
10084
|
+
{
|
|
10085
|
+
// Se paga el soporte extendido para recibir parches y no se aplican solos. Medium: no afirma ninguna vulnerabilidad.
|
|
10086
|
+
id: "COMBO_AWS_RDS_EXTENDED_NO_AUTO_MINOR",
|
|
10087
|
+
provider: "aws",
|
|
10088
|
+
resourceKind: "rds_instance",
|
|
10089
|
+
severity: "medium",
|
|
10090
|
+
rules: ["SEC_AWS_PATCHING_RDS_SIN_ACTUALIZACION_MENOR"],
|
|
10091
|
+
costRules: ["DATABASE_RDS_EXTENDED_SUPPORT"],
|
|
10092
|
+
detect: (input) => withCostSignal(input, {
|
|
10093
|
+
rule: "SEC_AWS_PATCHING_RDS_SIN_ACTUALIZACION_MENOR",
|
|
10094
|
+
costRule: "DATABASE_RDS_EXTENDED_SUPPORT",
|
|
10095
|
+
findingKey: (f) => `${f.region}::${f.resourceId}`,
|
|
10096
|
+
signalKey: (s) => `${s.region}::${s.resourceId}`,
|
|
10097
|
+
amount: true
|
|
10098
|
+
// El aviso de «entra en soporte extendido en ≤60 días» lleva importe 0: aún no se paga nada.
|
|
10099
|
+
}).filter((m) => typeof m.evidence["monthlySavingsUsd"] === "number" && m.evidence["monthlySavingsUsd"] > 0)
|
|
10100
|
+
},
|
|
9934
10101
|
{
|
|
9935
10102
|
// Dos defensas que faltan a la vez: endpoint público (PubliclyAccessible) y datos sin cifrar en disco. No prueba la ruta de red completa.
|
|
9936
10103
|
id: "COMBO_AWS_PUBLIC_DB_UNENCRYPTED",
|
|
9937
10104
|
provider: "aws",
|
|
10105
|
+
resourceKind: "rds_instance",
|
|
9938
10106
|
severity: "critical",
|
|
9939
10107
|
rules: ["SEC_AWS_ENCRYPTION_RDS_SIN_CIFRAR", "SEC_AWS_EXPOSURE_RDS_PUBLICA"],
|
|
9940
10108
|
detect: (input) => sameResource(input, "SEC_AWS_ENCRYPTION_RDS_SIN_CIFRAR", "SEC_AWS_EXPOSURE_RDS_PUBLICA").map((m) => ({ ...m, evidence: { publiclyAccessible: true } }))
|
|
@@ -9943,6 +10111,7 @@ var AWS_SECURITY_COMBOS = [
|
|
|
9943
10111
|
// Entra a la consola solo con contraseña y además tiene una clave de acceso vieja y activa: dos puertas sin segundo factor.
|
|
9944
10112
|
id: "COMBO_AWS_USER_NO_MFA_OLD_KEY",
|
|
9945
10113
|
provider: "aws",
|
|
10114
|
+
resourceKind: "iam_user",
|
|
9946
10115
|
severity: "critical",
|
|
9947
10116
|
rules: ["SEC_AWS_IAM_USUARIO_SIN_MFA", "SEC_AWS_IAM_CLAVE_ANTIGUA"],
|
|
9948
10117
|
detect: (input) => {
|
|
@@ -9967,6 +10136,7 @@ var AWS_SECURITY_COMBOS = [
|
|
|
9967
10136
|
// Administrador efectivo, consola sin MFA y una clave activa que nadie usa: tres puertas a toda la cuenta y nadie mirando una de ellas.
|
|
9968
10137
|
id: "COMBO_AWS_ADMIN_NO_MFA_UNUSED_KEY",
|
|
9969
10138
|
provider: "aws",
|
|
10139
|
+
resourceKind: "iam_user",
|
|
9970
10140
|
severity: "critical",
|
|
9971
10141
|
rules: ["SEC_AWS_IAM_ADMIN_EFECTIVO", "SEC_AWS_IAM_USUARIO_SIN_MFA", "SEC_AWS_IAM_CLAVE_SIN_USO"],
|
|
9972
10142
|
detect: (input) => {
|
|
@@ -11665,6 +11835,34 @@ var ALARM_RULES = ALARM_CONTROLS.map((control) => ({
|
|
|
11665
11835
|
evaluate: (observations) => evaluateAlarmControl(control, observations)
|
|
11666
11836
|
}));
|
|
11667
11837
|
|
|
11838
|
+
// ../../services/security/src/rules/aws/patching.ts
|
|
11839
|
+
var SIN_ACTUALIZACION_MENOR_GESTIONADA = /^(custom-|docdb$|neptune$)/;
|
|
11840
|
+
function rdsSinActualizacionMenorEvaluate(observation) {
|
|
11841
|
+
const engine = observation.attributes.engine;
|
|
11842
|
+
if (typeof engine === "string" && SIN_ACTUALIZACION_MENOR_GESTIONADA.test(engine)) return { status: "ok" };
|
|
11843
|
+
const auto = observation.attributes.autoMinorVersionUpgrade;
|
|
11844
|
+
if (typeof auto !== "boolean") return { status: "unknown", check: RDS_CHECKS.instances, attribute: "autoMinorVersionUpgrade" };
|
|
11845
|
+
if (auto) return { status: "ok" };
|
|
11846
|
+
return {
|
|
11847
|
+
status: "finding",
|
|
11848
|
+
evidence: {
|
|
11849
|
+
autoMinorVersionUpgrade: false,
|
|
11850
|
+
engine: engine ?? null,
|
|
11851
|
+
engineVersion: observation.attributes.engineVersion ?? null
|
|
11852
|
+
}
|
|
11853
|
+
};
|
|
11854
|
+
}
|
|
11855
|
+
var rdsSinActualizacionMenor = {
|
|
11856
|
+
id: "SEC_AWS_PATCHING_RDS_SIN_ACTUALIZACION_MENOR",
|
|
11857
|
+
scope: "resource",
|
|
11858
|
+
category: "security_patching",
|
|
11859
|
+
severity: "medium",
|
|
11860
|
+
provider: "aws",
|
|
11861
|
+
kinds: ["rds_instance"],
|
|
11862
|
+
requires: [REGION_CHECKS.listRegions, RDS_CHECKS.instances],
|
|
11863
|
+
evaluate: rdsSinActualizacionMenorEvaluate
|
|
11864
|
+
};
|
|
11865
|
+
|
|
11668
11866
|
// ../../services/security/src/rules/aws/secrets.ts
|
|
11669
11867
|
var SOSPECHOSAS = [
|
|
11670
11868
|
"PASSWORD",
|
|
@@ -11725,6 +11923,7 @@ var AWS_SECURITY_RULES = [
|
|
|
11725
11923
|
lambdaPublica,
|
|
11726
11924
|
kmsSinRotacion,
|
|
11727
11925
|
rdsSinCifrar,
|
|
11926
|
+
rdsSinActualizacionMenor,
|
|
11728
11927
|
rootSinMfa,
|
|
11729
11928
|
usuarioSinMfa,
|
|
11730
11929
|
claveAntigua,
|
|
@@ -11749,6 +11948,7 @@ var AZURE_SECURITY_COMBOS = [
|
|
|
11749
11948
|
// Abierto a internet y con un TLS que admite versiones viejas: lo que viaja se puede leer por el camino.
|
|
11750
11949
|
id: "COMBO_AZURE_PUBLIC_SQL_WEAK_TLS",
|
|
11751
11950
|
provider: "azure",
|
|
11951
|
+
resourceKind: "sql_server",
|
|
11752
11952
|
severity: "high",
|
|
11753
11953
|
rules: ["SEC_AZURE_EXPOSURE_SQL_PUBLICO", "SEC_AZURE_ENCRYPTION_SQL_TLS"],
|
|
11754
11954
|
detect: (input) => sameResource(input, "SEC_AZURE_EXPOSURE_SQL_PUBLICO", "SEC_AZURE_ENCRYPTION_SQL_TLS")
|
|
@@ -11757,10 +11957,40 @@ var AZURE_SECURITY_COMBOS = [
|
|
|
11757
11957
|
// Permite contenedores públicos y además TLS débil o HTTP: la exposición de la cuenta se suma a la del tránsito.
|
|
11758
11958
|
id: "COMBO_AZURE_PUBLIC_STORAGE_WEAK_TLS",
|
|
11759
11959
|
provider: "azure",
|
|
11960
|
+
resourceKind: "storage_account",
|
|
11760
11961
|
severity: "critical",
|
|
11761
11962
|
rules: ["SEC_AZURE_EXPOSURE_BLOB_PUBLICO", "SEC_AZURE_ENCRYPTION_STORAGE_TLS"],
|
|
11762
11963
|
detect: (input) => sameResource(input, "SEC_AZURE_EXPOSURE_BLOB_PUBLICO", "SEC_AZURE_ENCRYPTION_STORAGE_TLS")
|
|
11763
11964
|
},
|
|
11965
|
+
{
|
|
11966
|
+
// Servidor abierto a internet con bases que llevan una semana sin conexiones: se paga por datos expuestos que nadie usa.
|
|
11967
|
+
id: "COMBO_AZURE_PUBLIC_SQL_IDLE",
|
|
11968
|
+
provider: "azure",
|
|
11969
|
+
resourceKind: "sql_server",
|
|
11970
|
+
severity: "high",
|
|
11971
|
+
rules: ["SEC_AZURE_EXPOSURE_SQL_PUBLICO"],
|
|
11972
|
+
costRules: ["AZURE_SQL_ZERO_CONN"],
|
|
11973
|
+
detect: (input) => {
|
|
11974
|
+
const sinUso = costSignalsOf(input, "AZURE_SQL_ZERO_CONN").filter((s) => s.armId);
|
|
11975
|
+
if (sinUso.length === 0) return [];
|
|
11976
|
+
return input.findings.filter((f) => f.ruleId === "SEC_AZURE_EXPOSURE_SQL_PUBLICO").flatMap((f) => {
|
|
11977
|
+
const prefijo2 = `${f.resourceId.toLowerCase()}/databases/`;
|
|
11978
|
+
const bases = sinUso.filter((s) => s.armId.toLowerCase().startsWith(prefijo2));
|
|
11979
|
+
const primera = bases[0];
|
|
11980
|
+
if (!primera) return [];
|
|
11981
|
+
const ahorro = Math.round(bases.reduce((total2, s) => total2 + s.monthlySavingsUsd, 0) * 100) / 100;
|
|
11982
|
+
return [
|
|
11983
|
+
{
|
|
11984
|
+
region: f.region,
|
|
11985
|
+
resourceId: f.resourceId,
|
|
11986
|
+
resourceName: f.resourceName,
|
|
11987
|
+
findingIds: [f.id],
|
|
11988
|
+
evidence: { ...costEvidence(input, { ...primera, monthlySavingsUsd: ahorro }, { amount: true }), idleDatabases: bases.length }
|
|
11989
|
+
}
|
|
11990
|
+
];
|
|
11991
|
+
});
|
|
11992
|
+
}
|
|
11993
|
+
},
|
|
11764
11994
|
{
|
|
11765
11995
|
// VM expuesta a internet según Defender y con un CVE crítico o alto con exploit conocido.
|
|
11766
11996
|
id: "COMBO_AZURE_PUBLIC_VULNERABLE",
|
|
@@ -12228,18 +12458,36 @@ var GCP_SECURITY_COMBOS = [
|
|
|
12228
12458
|
// Abierta a internet, sin uso en 7 días y facturando: se paga por una puerta que nadie usa.
|
|
12229
12459
|
id: "COMBO_GCP_PUBLIC_SQL_IDLE",
|
|
12230
12460
|
provider: "gcp",
|
|
12461
|
+
resourceKind: "cloud_sql_instance",
|
|
12231
12462
|
severity: "high",
|
|
12232
12463
|
rules: ["SEC_GCP_EXPOSURE_SQL_PUBLICO"],
|
|
12233
12464
|
costRules: ["GCP_SQL_ZERO_CONNECTIONS"],
|
|
12234
|
-
detect: (input) => {
|
|
12235
|
-
|
|
12236
|
-
|
|
12237
|
-
|
|
12238
|
-
|
|
12239
|
-
|
|
12240
|
-
|
|
12241
|
-
|
|
12242
|
-
|
|
12465
|
+
detect: (input) => withCostSignal(input, {
|
|
12466
|
+
rule: "SEC_GCP_EXPOSURE_SQL_PUBLICO",
|
|
12467
|
+
costRule: "GCP_SQL_ZERO_CONNECTIONS",
|
|
12468
|
+
// Por nombre: coste y seguridad usan el nombre de la instancia, único dentro del proyecto.
|
|
12469
|
+
findingKey: (f) => f.resourceId,
|
|
12470
|
+
signalKey: (s) => s.resourceId,
|
|
12471
|
+
amount: true
|
|
12472
|
+
})
|
|
12473
|
+
},
|
|
12474
|
+
{
|
|
12475
|
+
// Guarda credenciales en su configuración y nadie la invoca: borrarla quita las credenciales del proyecto sin romper nada.
|
|
12476
|
+
id: "COMBO_GCP_UNUSED_FUNCTION_SECRETS",
|
|
12477
|
+
provider: "gcp",
|
|
12478
|
+
resourceKind: "cloud_function",
|
|
12479
|
+
severity: "high",
|
|
12480
|
+
rules: ["SEC_GCP_SECRETS_FUNCTION_ENV"],
|
|
12481
|
+
costRules: ["GCP_FUNCTION_UNUSED"],
|
|
12482
|
+
detect: (input) => withCostSignal(input, {
|
|
12483
|
+
rule: "SEC_GCP_SECRETS_FUNCTION_ENV",
|
|
12484
|
+
costRule: "GCP_FUNCTION_UNUSED",
|
|
12485
|
+
// Los dos módulos usan el nombre completo (projects/…/locations/…/functions/…), que ya lleva la región.
|
|
12486
|
+
findingKey: (f) => f.resourceId,
|
|
12487
|
+
signalKey: (s) => s.resourceId,
|
|
12488
|
+
// El módulo de coste no pone precio a una función: depende del uso.
|
|
12489
|
+
amount: false
|
|
12490
|
+
})
|
|
12243
12491
|
},
|
|
12244
12492
|
{
|
|
12245
12493
|
// Una cuenta de servicio Owner o Editor con una clave descargable: quien tenga el fichero tiene el proyecto.
|
package/package.json
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@aaa-sentinel/iac-cost",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Estimate the monthly cost delta of a Terraform plan, check it against the AAA Sentinel security rules, open security fixes as pull requests and report how the security posture changed, from your CI",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"bin": {
|
|
8
|
-
"iac-cost": "dist/cli.js"
|
|
9
|
-
},
|
|
10
|
-
"files": [
|
|
11
|
-
"dist"
|
|
12
|
-
],
|
|
13
|
-
"keywords": [
|
|
14
|
-
"terraform",
|
|
15
|
-
"finops",
|
|
16
|
-
"cost",
|
|
17
|
-
"iac",
|
|
18
|
-
"security",
|
|
19
|
-
"shift-left"
|
|
20
|
-
],
|
|
21
|
-
"publishConfig": {
|
|
22
|
-
"access": "public"
|
|
23
|
-
},
|
|
24
|
-
"homepage": "https://app.aaa-sentinel.com/developer/docs#terraform-ci",
|
|
25
|
-
"bugs": {
|
|
26
|
-
"url": "https://app.aaa-sentinel.com/contact"
|
|
27
|
-
},
|
|
28
|
-
"engines": {
|
|
29
|
-
"node": ">=20"
|
|
30
|
-
},
|
|
31
|
-
"scripts": {
|
|
32
|
-
"build": "esbuild src/cli.ts --bundle --platform=node --format=esm --target=node20 --outfile=dist/cli.js",
|
|
33
|
-
"prepublishOnly": "npm --prefix ../.. run build:iac-cost",
|
|
34
|
-
"test": "vitest run"
|
|
35
|
-
},
|
|
36
|
-
"devDependencies": {
|
|
37
|
-
"@finops-sentinel/shared": "*",
|
|
38
|
-
"@types/node": "^22.0.0",
|
|
39
|
-
"esbuild": "^0.24.0",
|
|
40
|
-
"typescript": "^5.7.0",
|
|
41
|
-
"vitest": "^3.2.0"
|
|
42
|
-
}
|
|
43
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@aaa-sentinel/iac-cost",
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "Estimate the monthly cost delta of a Terraform plan, check it against the AAA Sentinel security rules, open security fixes as pull requests and report how the security posture changed, from your CI",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"iac-cost": "dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"keywords": [
|
|
14
|
+
"terraform",
|
|
15
|
+
"finops",
|
|
16
|
+
"cost",
|
|
17
|
+
"iac",
|
|
18
|
+
"security",
|
|
19
|
+
"shift-left"
|
|
20
|
+
],
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://app.aaa-sentinel.com/developer/docs#terraform-ci",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://app.aaa-sentinel.com/contact"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=20"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "esbuild src/cli.ts --bundle --platform=node --format=esm --target=node20 --outfile=dist/cli.js",
|
|
33
|
+
"prepublishOnly": "npm --prefix ../.. run build:iac-cost",
|
|
34
|
+
"test": "vitest run"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@finops-sentinel/shared": "*",
|
|
38
|
+
"@types/node": "^22.0.0",
|
|
39
|
+
"esbuild": "^0.24.0",
|
|
40
|
+
"typescript": "^5.7.0",
|
|
41
|
+
"vitest": "^3.2.0"
|
|
42
|
+
}
|
|
43
|
+
}
|