Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom fields to reports directly within the policy yaml #9481

Open
nitrocode opened this issue May 5, 2024 · 0 comments
Open

Add custom fields to reports directly within the policy yaml #9481

nitrocode opened this issue May 5, 2024 · 0 comments

Comments

@nitrocode
Copy link
Contributor

nitrocode commented May 5, 2024

Describe the feature

I am always frustrated when I have to recall a specific field for a specific policy that I need to report on.

https://cloudcustodian.io/docs/quickstart/advanced.html

It would be nice if I could codify the field itself within the policy so I can run my reports without having to recall the specific command or without having to run different commands per report.

e.g. instead of this

custodian report -s . \
  --field "AccessKey1LastRotated"='"c7n:credential-report".access_keys[0].last_rotated' \
  policies/iam-unused.yml

I can add this to my policy

policies:
  - name: iam-deactivate-old-keys
    resource: iam-user
    conditions:
      - region: us-east-1
+   report:
+     default_fields: true
+     fields:
+       - key: AccessKey1LastRotated
+         value: "\"c7n:credential-report\".access_keys[0].last_rotated"
    filters:
      - type: credential
        key: access_keys.active
        value: true
        op: eq
      - type: credential
        key: access_keys.last_rotated
        value_type: age
        value: 30
        op: greater-than
      - type: credential
        key: access_keys.last_used_date
        value_type: age
        value: 365
        op: greater-than
      # Workaround in https://github.com/cloud-custodian/cloud-custodian/issues/5583#issuecomment-1603010775
      - type: value
        key: length("c7n:matched-keys")
        value: 1
        op: gte

and simply run the report bare

custodian report -s . policies/iam-unused.yml

Extra information or context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant