Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions components/buckets/new-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function BucketNewForm({ show, onShowChange }: BucketNewFormProps) {
const { t } = useTranslation()
const message = useMessage()
const { createBucket, putBucketVersioning, putObjectLockConfiguration, putBucketQuota } = useBucket()
const { canCapability, checkCapability } = usePermissions()
const { canCapability, mayCapability, checkCapability } = usePermissions()

const [objectKey, setObjectKey] = React.useState("")
const [version, setVersion] = React.useState(false)
Expand All @@ -62,7 +62,11 @@ export function BucketNewForm({ show, onShowChange }: BucketNewFormProps) {
const parsedRetentionPeriod = Math.max(1, Number.parseInt(retentionPeriod, 10) || 1)
const isSubmitDisabled = creating || !trimmedBucketName || !!nameError
const bucketContext = trimmedBucketName ? { bucket: trimmedBucketName } : {}
const canCreateBucket = !!trimmedBucketName && canCapability("bucket.create", bucketContext)
// Bucket names are user input. On legacy servers the browser cannot
// evaluate resource variables such as ${aws:userid}, so discoverability
// uses the action-potential check and the actual CreateBucket request remains
// the authorization boundary.
const canCreateBucket = !!trimmedBucketName && mayCapability("bucket.create", bucketContext)
const canEditVersioning = canCapability("bucket.versioning.edit", bucketContext)
const canEditObjectLock = canCapability("bucket.objectLock.edit", bucketContext)
const canEditQuota = canCapability("bucket.quota.edit", bucketContext)
Expand Down
3 changes: 3 additions & 0 deletions hooks/use-permissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ export function PermissionsProvider({ children }: { children: React.ReactNode })
if (permissionClient.status === "unsupported") {
const snapshot = legacyPolicy.current
if (snapshot.client !== permissionClient) return false
if (capability === "bucket.create") {
return snapshot.isAdmin || hasConsoleActionPotential(snapshot.userPolicy, "s3:CreateBucket")
}
if (capability === "objects.forceCleanup")
return snapshot.isOwner || hasConsoleCapability(snapshot.userPolicy, capability, context)
return snapshot.isAdmin || hasConsoleCapability(snapshot.userPolicy, capability, context)
Expand Down
2 changes: 1 addition & 1 deletion lib/effective-permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export class EffectivePermissionClient {
const status = error && typeof error === "object" && "status" in error ? error.status : undefined
if (this.active && generation === this.generation)
this.status =
!this.supportedEndpoint && [404, 405, 501].includes(Number(status)) ? "unsupported" : "unavailable"
!this.supportedEndpoint && [404, 405, 426, 501].includes(Number(status)) ? "unsupported" : "unavailable"
failed = true
results = requests.map(() => UNKNOWN)
}
Expand Down
47 changes: 47 additions & 0 deletions tests/hooks/effective-permissions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,53 @@ test("an explicitly empty warehouse object retains the bucket ARN on a legacy se
assert.ok(mounted.requests.some((request) => request.object === ""))
})

test("legacy bucket creation uses action potential when a resource variable cannot be resolved", async (t) => {
const mounted = await mount(
t,
() => {
throw Object.assign(new Error("Unsupported"), { status: 426 })
},
JSON.stringify({
Version: "2012-10-17",
Statement: [
{
Effect: "Allow",
Action: ["s3:CreateBucket"],
Resource: ["arn:aws:s3:::${aws:userid}", "arn:aws:s3:::${aws:userid}-*"],
},
],
}),
)
await act(async () => {
await mounted.permissions.loadAction({ action: "s3:CreateBucket", context: { bucket: "fixture-alice-project" } })
assert.equal(mounted.permissions.mayCapability("bucket.create", { bucket: "fixture-alice-project" }), true)
})
let allowed = false
await act(async () => {
allowed = await mounted.permissions.checkCapability("bucket.create", { bucket: "fixture-alice-project" })
})
assert.equal(allowed, true)
assert.equal(mounted.permissions.mayCapability("bucket.create", { bucket: "other-user-project" }), true)
})

test("legacy bucket creation remains unavailable when the action is absent", async (t) => {
const mounted = await mount(
t,
() => {
throw Object.assign(new Error("Unsupported"), { status: 426 })
},
JSON.stringify({
Version: "2012-10-17",
Statement: [{ Effect: "Allow", Action: ["s3:ListBucket"], Resource: ["arn:aws:s3:::${aws:userid}-*"] }],
}),
)
await act(async () => {
await mounted.permissions.loadAction({ action: "s3:CreateBucket", context: { bucket: "fixture-alice-project" } })
})
assert.equal(mounted.permissions.mayCapability("bucket.create", { bucket: "fixture-alice-project" }), false)
assert.equal(await mounted.permissions.checkCapability("bucket.create", { bucket: "fixture-alice-project" }), false)
})

test("a server-side session or condition denial overrides a broad identity projection", async (t) => {
const mounted = await mount(t, () => ({ decision: "denied" }))
let allowed = true
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/effective-permissions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,17 @@ for (const status of [401, 403, 500]) {
})
}

test("HTTP 426 selects legacy compatibility for older permission endpoints", async () => {
const client = new EffectivePermissionClient(
async () => {
throw Object.assign(new Error("upgrade required"), { status: 426 })
},
() => {},
)
await client.load(check)
assert.equal(client.status, "unsupported")
})

test("an absent endpoint selects explicit legacy compatibility", async () => {
const client = new EffectivePermissionClient(
async () => {
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/form-interaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ test("object lock and versioning change together, and a pending bucket creation
useBucket: () => api,
usePermissions: () => ({
canCapability: () => true,
mayCapability: () => true,
checkCapability: async (...args: unknown[]) => {
permissionChecks.push(args)
return true
Expand Down Expand Up @@ -323,7 +324,7 @@ test("enabling bucket retention explains lifecycle expiration limits", async (t)
const switches = new Map<string, { onCheckedChange: (value: boolean) => void }>()
const { container } = await mount(t, React.createElement(BucketNewForm, { show: true, onShowChange: () => {} }), {
useBucket: () => ({}),
usePermissions: () => ({ canCapability: () => true }),
usePermissions: () => ({ canCapability: () => true, mayCapability: () => true }),
useMessage: () => ({ error: () => {}, success: () => {} }),
getOptionalBucketNameError: () => null,
cn: (...values: unknown[]) => values.filter(Boolean).join(" "),
Expand Down