File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change 4
4
IGrantable ,
5
5
PolicyStatement ,
6
6
} from 'aws-cdk-lib/aws-iam' ;
7
- import { IKey } from 'aws-cdk-lib/aws-kms' ;
7
+ import { IKey , ViaServicePrincipal } from 'aws-cdk-lib/aws-kms' ;
8
8
import {
9
9
ISecret ,
10
10
ISecretAttachmentTarget ,
@@ -129,6 +129,15 @@ export class SopsSecret extends Construct implements ISecret {
129
129
}
130
130
131
131
public grantRead ( grantee : IGrantable , versionStages ?: string [ ] ) : Grant {
132
+ if ( this . encryptionKey ) {
133
+ // @see https://docs.aws.amazon.com/kms/latest/developerguide/services-secrets-manager.html
134
+ this . encryptionKey . grantDecrypt (
135
+ new ViaServicePrincipal (
136
+ `secretsmanager.${ Stack . of ( this ) . region } .amazonaws.com` ,
137
+ grantee . grantPrincipal ,
138
+ ) ,
139
+ ) ;
140
+ }
132
141
return this . secret . grantRead ( grantee , versionStages ) ;
133
142
}
134
143
public grantWrite ( _grantee : IGrantable ) : Grant {
Original file line number Diff line number Diff line change @@ -92,9 +92,15 @@ export class SopsStringParameter extends Construct implements IStringParameter {
92
92
} ) ;
93
93
}
94
94
grantRead ( grantee : IGrantable ) : Grant {
95
+ if ( this . encryptionKey ) {
96
+ this . encryptionKey . grantDecrypt ( grantee ) ;
97
+ }
95
98
return this . parameter . grantRead ( grantee ) ;
96
99
}
97
100
grantWrite ( grantee : IGrantable ) : Grant {
101
+ if ( this . encryptionKey ) {
102
+ this . encryptionKey . grantEncrypt ( grantee ) ;
103
+ }
98
104
return this . parameter . grantWrite ( grantee ) ;
99
105
}
100
106
applyRemovalPolicy ( policy : RemovalPolicy ) : void {
You can’t perform that action at this time.
0 commit comments