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
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,25 @@ const setPolicy2 = () => {
},
});
};
const setPolicy3 = () => {
store.dispatch({
type: SESSION_RESPONSE,
message: {
distributedMode: true,
features: [],
permissions: {
"arn:aws:s3:::testbucket-*": [
"admin:CreateServiceAccount",
"s3:*",
"admin:CreateUser",
],
"console-ui": ["admin:CreateServiceAccount", "admin:CreateUser"],
},
status: "ok",
operator: false,
},
});
};

test("Upload button disabled", () => {
setPolicy1();
Expand Down Expand Up @@ -123,3 +142,18 @@ test("Can List Objects In Bucket", () => {
setPolicy2();
expect(hasPermission("bucket-svc", [IAM_SCOPES.S3_LIST_BUCKET])).toBe(true);
});

test("Can create bucket for policy with a wildcard", () => {
setPolicy3();
expect(hasPermission("*", [IAM_SCOPES.S3_CREATE_BUCKET])).toBe(true);
});

test("Can browse a bucket for a policy with a wildcard", () => {
setPolicy3();
expect(
hasPermission(
"testbucket-0",
IAM_PAGES_PERMISSIONS[IAM_PAGES.BUCKETS_BROWSE_VIEW]
)
).toBe(true);
});
22 changes: 20 additions & 2 deletions portal-ui/src/common/SecureComponent/accessControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const hasPermission = (

const replaceWildcard = wildcardItemSection
.replace("/", "\\/")
.replace("\\/*", "($|(\\/.*?))");
.replace("*", "($|\\/?(.*?))");

const inRegExp = new RegExp(`${replaceWildcard}$`, "gm");

Expand Down Expand Up @@ -105,8 +105,26 @@ const hasPermission = (
});
}

let anyResourceGrant: string[] = [];
if (resource === "*") {
Object.entries(sessionGrants).forEach(([key, values]) => {
scopes.forEach((scope) => {
values.forEach((val) => {
if (val === scope || val === "s3:*") {
anyResourceGrant = [...anyResourceGrant, scope];
}
});
});
});
}

return hasAccessToResource(
[...resourceGrants, ...globalGrants, ...containsResourceGrants],
[
...resourceGrants,
...globalGrants,
...containsResourceGrants,
...anyResourceGrant,
],
scopes,
matchAll
);
Expand Down
33 changes: 13 additions & 20 deletions portal-ui/src/screens/Console/Buckets/ListBuckets/ListBuckets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import SearchBox from "../../Common/SearchBox";
import VirtualizedList from "../../Common/VirtualizedList/VirtualizedList";
import RBIconButton from "../BucketDetails/SummaryItems/RBIconButton";
import BulkLifecycleModal from "./BulkLifecycleModal";
import hasPermission from "../../../../common/SecureComponent/accessControl";

const styles = (theme: Theme) =>
createStyles({
Expand Down Expand Up @@ -200,10 +201,7 @@ const ListBuckets = ({
return null;
};

const createBucketButtonResources: string[] =
session && session.permissions
? Array.from(Object.keys(session.permissions)) || []
: [];
const canCreateBucket = hasPermission("*", [IAM_SCOPES.S3_CREATE_BUCKET]);

return (
<Fragment>
Expand Down Expand Up @@ -293,22 +291,17 @@ const ListBuckets = ({
variant={"outlined"}
/>

<SecureComponent
scopes={[IAM_SCOPES.S3_CREATE_BUCKET]}
resource={createBucketButtonResources}
errorProps={{ disabled: true }}
>
<RBIconButton
tooltip={"Create Bucket"}
onClick={() => {
history.push("/add-bucket");
}}
text={"Create Bucket"}
icon={<AddIcon />}
color={"primary"}
variant={"contained"}
/>
</SecureComponent>
<RBIconButton
tooltip={"Create Bucket"}
onClick={() => {
history.push("/add-bucket");
}}
text={"Create Bucket"}
icon={<AddIcon />}
color={"primary"}
variant={"contained"}
disabled={!canCreateBucket}
/>
</Grid>
</Grid>

Expand Down
9 changes: 1 addition & 8 deletions portal-ui/src/screens/Console/Console.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,7 @@ const Console = ({
component: Buckets,
path: IAM_PAGES.ADD_BUCKETS,
customPermissionFnc: () => {
const createBucketResources: string[] =
session && session.permissions
? Array.from(Object.keys(session.permissions)) || []
: [];
return hasPermission(
createBucketResources,
IAM_PAGES_PERMISSIONS[IAM_PAGES.ADD_BUCKETS]
);
return hasPermission("*", IAM_PAGES_PERMISSIONS[IAM_PAGES.ADD_BUCKETS]);
},
},
{
Expand Down