Skip to content

Comments

Create "raw" managed policy using existing class props#2822

Open
aug24 wants to merge 13 commits intomainfrom
raw-managed-policies
Open

Create "raw" managed policy using existing class props#2822
aug24 wants to merge 13 commits intomainfrom
raw-managed-policies

Conversation

@aug24
Copy link
Contributor

@aug24 aug24 commented Feb 19, 2026

What does this change?

This PR provides a base class for provision of an AWS Managed Policy with specific, discoverable, characteristics. These should be used to create Developer Policies which can be granted as needed with temporary credentials for short term workloads.

How to test

How can we measure success?

Have we considered potential risks?

Checklist

  • I have listed any breaking changes, along with a migration path 1
  • I have updated the documentation as required for the described changes 2

Footnotes

  1. Consider whether this is something that will mean changes to projects that have already been migrated, or to the CDK CLI tool. If changes are required, consider adding a checklist here and/or linking to related PRs.

  2. If you are adding a new construct or pattern, has new documentation been added? If you are amending defaults or changing behaviour, are the existing docs still valid?

@changeset-bot
Copy link

changeset-bot bot commented Feb 19, 2026

🦋 Changeset detected

Latest commit: 29190f3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@guardian/cdk Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@aug24 aug24 added the feature Departmental tracking: work on a new feature label Feb 19, 2026
Copy link
Member

@kelvin-chappell kelvin-chappell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


export class GuDeveloperPolicy extends ManagedPolicy {
constructor(scope: GuStack, id: string, props: GuDeveloperPolicyProps) {
super(scope, id, { path: `/developer-policy/${props.permission}/`, ...props });
Copy link
Member

@akash1810 akash1810 Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spreading props last would mean any values contained within wins. That is, if we have:

const myProps: GuDeveloperPolicyProps = {
  path: 'my/own/value'
}

new GuDeveloperPolicy(myProps);

Then /developer-policy/??? will be overridden to my/own/value.

I think there are a couple of options to resolve:

  • Spreading props first and setting path second
  • Have the GuDeveloperPolicyProps interface Omit the path property from ManagedPolicyProps

Copy link
Contributor Author

@aug24 aug24 Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually chose this hierarchy on purpose when this was intended as a generic managed policy object then we decided to make it dedicated. I think I'll just remove the facility to set for yourself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've gone back and pruned the props much harder - this class shouldn't be used to grant policies to roles, user, or groups, so I've enforced that by Omit'ing them.

Comment on lines 6 to 11
export type GuDeveloperPolicyProps = Omit<ManagedPolicyProps, "statements"> & {
allow: GuAllowPolicyProps[];
deny?: GuDenyPolicyProps[];
permission: string;
description?: string;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add some doc strings to these properties?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might name be more descriptive, replacing permission?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Permission is the deliberate choice for the UI. So I think we'd prefer to keep the nomenclature the same. It's the permission you're getting.

description?: string;
};

export class GuDeveloperPolicy extends ManagedPolicy {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a doc string to this class to describe when/how/why to use it, please?

"@guardian/cdk": minor
---

Create "raw" managed policy using existing class props
Copy link
Member

@akash1810 akash1810 Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These notes make their way into the CHANGELOG and the release notes. Would they benefit from more detail? For example, covering when to use the new construct, the name of the new construct, and maybe a concrete example1?

Footnotes

  1. Whilst the tests provide example implementations, they don't really cover real-life situations (assuming a permission should be more descriptive than test123?)

Comment on lines 6 to 11
export type GuDeveloperPolicyProps = Omit<ManagedPolicyProps, "users" | "roles" | "groups" | "statements" | "path"> & {
allow: GuAllowPolicyProps[];
deny?: GuDenyPolicyProps[];
permission: string;
description?: string;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC the remaining properties from ManagedPolicyProps are: document and managedPolicyName. We're defaulting the latter to permission. Are we expecting document to be set? If not, it might not be worth extending ManagedPolicyProps at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's getting a bit thin, isn't it. I'm allowing statements and document to be set, in case people prefer to use really raw content, but it's a bit weak. Name and path are defaulted, not forced, so could be set.

But the main reason I would expect to do this is because these properties are then passed into the super call. If a parameter were to be added to ManagedPolicy, this should flow through.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed my mind. The friendly name restriction is too dangerous.

Comment on lines 7 to 10
allow: GuAllowPolicyProps[];
deny?: GuDenyPolicyProps[];
permission: string;
description?: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we document these properties please? TypeDoc strings make their way to the documentation site.

@aug24 aug24 force-pushed the raw-managed-policies branch 2 times, most recently from fbeca4a to 9bce0a1 Compare February 23, 2026 16:33
@aug24 aug24 force-pushed the raw-managed-policies branch from 8e86a42 to 29190f3 Compare February 24, 2026 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Departmental tracking: work on a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants