Skip to content

Commit

Permalink
Merge branch 'improvement/ZKUI-207-disable-remove-button-for-backbeat…
Browse files Browse the repository at this point in the history
…-policy' into tmp/octopus/w/1.5/improvement/ZKUI-207-disable-remove-button-for-backbeat-policy
  • Loading branch information
bert-e committed Jul 1, 2022
2 parents 724ca8c + 741aaa6 commit e008df2
Show file tree
Hide file tree
Showing 7 changed files with 270 additions and 2 deletions.
230 changes: 230 additions & 0 deletions public/assets/account-seeds.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
[
{
"role": {
"roleName": "storage-manager-role",
"trustPolicy": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Federated": "keycloak.zenko.local" },
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"keycloak:roles": "StorageManager"
}
}
}
]
}
},
"permissionPolicy": {
"policyName": "storage-manager-policy",
"policyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Sid": "FullAccess",
"Effect": "Allow",
"Action": ["*"],
"Resource": "*"
}
]
}
}
},
{
"role": {
"roleName": "storage-account-owner-role",
"trustPolicy": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Federated": "keycloak.zenko.local" },
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": { "keycloak:groups": "StorageAccountOwner" }
}
}
]
}
},
"permissionPolicy": {
"policyName": "storage-account-owner-policy",
"policyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Sid": "FullAccess",
"Effect": "Allow",
"Action": ["s3:*", "iam:*"],
"Resource": ["*"]
}
]
}
}
},
{
"role": {
"roleName": "data-consumer-role",
"trustPolicy": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Federated": "keycloak.zenko.local" },
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": { "keycloak:groups": "DataConsumer" }
}
}
]
}
},
"permissionPolicy": {
"policyName": "data-consumer-policy",
"policyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:ListAllMyBuckets",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": ["s3:ListBucket", "s3:GetBucketLocation"],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"s3:MetadataSearch",
"s3:PutObject",
"s3:PutObjectAcl",
"s3:GetObject",
"s3:GetObjectAcl",
"s3:DeleteObject",
"s3:RestoreObject",
"s3:GetBucketVersioning",
"s3:GetBucketCors",
"s3:GetBucketAcl",
"s3:GetBucketObjectLockConfiguration",
"s3:ListObjectsV2",
"s3:ListObjectVersions",
"s3:PutObjectLockConfiguration",
"s3:DeleteObjects",
"s3:GetObjectRetention",
"s3:GetObjectLegalHold",
"s3:PutObjectRetention",
"s3:PutObjectLegalHold",
"s3:HeadObject",
"s3:CopyObject",
"s3:GetObjectTagging",
"s3:PutObjectTagging",
"s3:GetReplicationConfiguration",
"s3:GetLifecycleConfiguration",
"s3:DeleteObjectVersion",
"s3:PutLifecycleConfiguration",
"s3:PutReplicationConfiguration",
"s3:ListObjectVersion",
"s3:GetObjectVersion",
"s3:GetObjectVersionRetention",
"s3:GetObjectVersionLegalHold",
"s3:PutObjectVersionRetention",
"s3:PutObjectVersionLegalHold",
"s3:GetObjectVersionTagging",
"s3:DeleteObjectVersionTagging",
"s3:PutObjectVersionTagging",
"s3:GetObjectVersionAcl",
"s3:PutObjectVersionAcl",
"s3:GetBucketTagging",
"s3:PutBucketTagging",
"s3:DeleteBucketTagging"
],
"Resource": "*"
}
]
}
}
},
{
"permissionPolicy": {
"policyDocument": {
"Statement": [
{
"Action": [
"s3:GetLifecycleConfiguration",
"s3:GetBucketVersioning",
"s3:ListBucket",
"s3:ListBucketVersions",
"s3:ListBucketMultipartUploads",
"s3:GetObjectTagging",
"s3:GetObjectVersionTagging",
"s3:GetObject",
"s3:GetObjectVersion"
],
"Effect": "Allow",
"Resource": ["*"],
"Sid": "LifecycleExpirationBucketProcessor"
}
],
"Version": "2012-10-17"
},
"policyName": "backbeat-lifecycle-bp-1"
},
"role": {
"roleName": "backbeat-lifecycle-bp-1",
"trustPolicy": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::000000000000:user/scality-internal/backbeat-lifecycle-bp-1"
}
}
],
"Version": "2012-10-17"
}
}
},
{
"permissionPolicy": {
"policyDocument": {
"Statement": [
{
"Action": [
"s3:GetObject",
"s3:GetObjectVersion",
"s3:DeleteObject",
"s3:DeleteObjectVersion",
"s3:AbortMultipartUpload"
],
"Effect": "Allow",
"Resource": ["*"],
"Sid": "LifecycleExpirationObjectProcessor"
}
],
"Version": "2012-10-17"
},
"policyName": "backbeat-lifecycle-op-1"
},
"role": {
"roleName": "backbeat-lifecycle-op-1",
"trustPolicy": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::000000000000:user/scality-internal/backbeat-lifecycle-op-1"
}
}
],
"Version": "2012-10-17"
}
}
}
]
11 changes: 11 additions & 0 deletions src/js/vault.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// TODO: AccountSeeds should be returned by Vault API
export function getAccountSeeds() {
return fetch('/account-seeds.json', {
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
}).then((res) => {
if (!res.ok) {
throw Error('Can not fetch Account Seeds!!');
}
return res.json();
});
}
1 change: 1 addition & 0 deletions src/react/account/iamAttachment/AttachmentTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ export const AttachmentTable = <
icon={<i className="fas fa-times"></i>}
label="Remove"
variant="danger"
disabled={!!entity.disableDetach}
/>
),
},
Expand Down
15 changes: 15 additions & 0 deletions src/react/account/iamAttachment/AttachmentTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { Loader } from '@scality/core-ui';
import { useReducer } from 'react';
import { useLocation, useParams } from 'react-router';
import { useTheme } from 'styled-components';
import { useQuery } from 'react-query';
import { useIAMClient } from '../../IAMProvider';
import {
getAccountSeedsQuery,
getListAttachedUserPoliciesQuery,
getListEntitiesForPolicyQuery,
getListGroupsQuery,
Expand Down Expand Up @@ -95,10 +97,12 @@ const AttachmentTableProxy = <
const AttachmentTabs = ({
resourceType,
resourceId,
resourceName,
onAttachmentsOperationsChanged,
}: {
resourceType: ResourceType;
resourceId: string;
resourceName: string;
onAttachmentsOperationsChanged: (
attachmentOperations: AttachmentOperation[],
) => void;
Expand Down Expand Up @@ -133,6 +137,12 @@ const AttachmentTabs = ({
tabLineColor: backgroundLevel4,
};

const { data: accountSeeds } = useQuery(getAccountSeedsQuery());
const policyRolePair =
accountSeeds?.filter(
(seed) => seed.permissionPolicy.policyName === resourceName,
) || [];

return (
<CustomTabs {...customTabStyle}>
{resourceType === 'policy' && (
Expand Down Expand Up @@ -289,10 +299,15 @@ const AttachmentTabs = ({
getAttachedEntitesFromResult={(response) => {
return (
response.PolicyRoles?.map((role) => {
const disableDetach =
!!policyRolePair.find(
(pair) => pair.role.roleName === role.RoleName,
) !== undefined;
return {
name: role.RoleName || '',
id: role.RoleName || '',
type: 'role',
disableDetach,
};
}) || []
);
Expand Down
1 change: 1 addition & 0 deletions src/react/account/iamAttachment/AttachmentTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type AttachableEntity = {
name: string;
id: string;
type: EntityType;
disableDetach?: boolean;
};

export enum AttachmentAction {
Expand Down
8 changes: 6 additions & 2 deletions src/react/account/iamAttachment/Attachments.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BasicText, EmphaseText, LargerText } from '@scality/core-ui';
import { Button } from '@scality/core-ui/dist/next';
import { useState } from 'react';
import { useParams, useRouteMatch } from 'react-router';
import styled from 'styled-components';
Expand Down Expand Up @@ -75,6 +74,7 @@ const Attachments = () => {
<AttachmentTabs
resourceId={resourceId}
resourceType={resourceType}
resourceName={resourceName}
onAttachmentsOperationsChanged={setAttachmentOperations}
/>
</AttachmentContainer>
Expand All @@ -84,7 +84,11 @@ const Attachments = () => {
resourceId={resourceId}
resourceName={resourceName}
resourceType={resourceType}
redirectUrl={isAttachToPolicy ? `/accounts/${account?.Name}/policies` : `/accounts/${account?.Name}/users`}
redirectUrl={
isAttachToPolicy
? `/accounts/${account?.Name}/policies`
: `/accounts/${account?.Name}/users`
}
/>
</AttachmentFooterContainer>
</>
Expand Down
6 changes: 6 additions & 0 deletions src/react/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { APIWorkflows, Workflows, Workflow } from '../types/workflow';
import { generateExpirationName, generateStreamName } from './workflow/utils';
import IAMClient from '../js/IAMClient';
import { QueryFunctionContext } from 'react-query';
import { getAccountSeeds } from '../js/vault';

// Copy paste form legacy redux workflow
export const makeWorkflows = (apiWorkflows: APIWorkflows): Workflows => {
Expand Down Expand Up @@ -161,3 +162,8 @@ export const getListAttachedUserPoliciesQuery = (
refetchOnMount: false,
refetchOnWindowFocus: false,
});

export const getAccountSeedsQuery = () => ({
queryKey: ['AccountSeeds'],
queryFn: getAccountSeeds,
});

0 comments on commit e008df2

Please sign in to comment.