@cytario/web 2.2.2 → 2.2.3
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.
|
@@ -52,7 +52,9 @@ const fetchTemporaryCredentials = async (
|
|
|
52
52
|
// Non-AWS providers (e.g. MinIO) may ignore or reject the `Policy` field,
|
|
53
53
|
// so we omit it there — the role's intrinsic scope is the only bound.
|
|
54
54
|
const sessionPolicy =
|
|
55
|
-
provider === "aws"
|
|
55
|
+
provider === "aws"
|
|
56
|
+
? buildSessionPolicy({ bucketName, prefix, region: actualRegion })
|
|
57
|
+
: undefined;
|
|
56
58
|
|
|
57
59
|
const command = new AssumeRoleWithWebIdentityCommand({
|
|
58
60
|
RoleArn: roleArn ?? undefined,
|
|
@@ -12,12 +12,13 @@
|
|
|
12
12
|
export interface SessionPolicyArgs {
|
|
13
13
|
bucketName: string;
|
|
14
14
|
prefix: string | null | undefined;
|
|
15
|
+
region: string;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
const stripSlashes = (prefix: string): string => prefix.replace(/^\/+|\/+$/g, "");
|
|
18
19
|
|
|
19
20
|
/** Build an inline IAM session policy for `AssumeRoleWithWebIdentityCommand`. */
|
|
20
|
-
export const buildSessionPolicy = ({ bucketName, prefix }: SessionPolicyArgs): string => {
|
|
21
|
+
export const buildSessionPolicy = ({ bucketName, prefix, region }: SessionPolicyArgs): string => {
|
|
21
22
|
const normalised = typeof prefix === "string" ? stripSlashes(prefix) : "";
|
|
22
23
|
// Defense-in-depth: refuse wildcards here so the schema is not the only gate
|
|
23
24
|
// protecting cross-tenant `StringLike` conditions.
|
|
@@ -52,6 +53,23 @@ export const buildSessionPolicy = ({ bucketName, prefix }: SessionPolicyArgs): s
|
|
|
52
53
|
Resource: bucketArn,
|
|
53
54
|
};
|
|
54
55
|
|
|
56
|
+
// STS intersects this policy with the role's attached policy. Without an
|
|
57
|
+
// explicit `kms:Decrypt` here, the role's KMS grant is stripped and
|
|
58
|
+
// `GetObject` against SSE-KMS-encrypted buckets fails. `kms:ViaService`
|
|
59
|
+
// restricts use of the minted credential to the S3 data path; the role's
|
|
60
|
+
// attached policy remains the authoritative key allowlist.
|
|
61
|
+
const decryptStatement = {
|
|
62
|
+
Sid: "DecryptViaS3",
|
|
63
|
+
Effect: "Allow",
|
|
64
|
+
Action: "kms:Decrypt",
|
|
65
|
+
Resource: "*",
|
|
66
|
+
Condition: {
|
|
67
|
+
StringEquals: {
|
|
68
|
+
"kms:ViaService": `s3.${region}.amazonaws.com`,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
|
|
55
73
|
const policy = {
|
|
56
74
|
Version: "2012-10-17",
|
|
57
75
|
Statement: [
|
|
@@ -62,6 +80,7 @@ export const buildSessionPolicy = ({ bucketName, prefix }: SessionPolicyArgs): s
|
|
|
62
80
|
Action: "s3:GetObject",
|
|
63
81
|
Resource: objectArn,
|
|
64
82
|
},
|
|
83
|
+
decryptStatement,
|
|
65
84
|
],
|
|
66
85
|
};
|
|
67
86
|
|
package/package.json
CHANGED