Skip to content

Commit ba478c6

Browse files
authored
feat(ecs): show more context for missing permissions #3798
ref #3797
1 parent 9f29f66 commit ba478c6

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "ECS: \"Insufficient permissions\" message shows more details about missing permissions"
4+
}

src/ecs/util.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import globals from '../shared/extensionGlobals'
88
import * as nls from 'vscode-nls'
99
const localize = nls.loadMessageBundle()
1010

11-
import * as vscode from 'vscode'
1211
import { EcsClient } from '../shared/clients/ecsClient'
1312
import { IamClient } from '../shared/clients/iamClient'
1413
import { ToolkitError } from '../shared/errors'
@@ -18,29 +17,29 @@ import { TaskDefinition } from 'aws-sdk/clients/ecs'
1817
import { getLogger } from '../shared/logger'
1918
import { SSM } from 'aws-sdk'
2019
import { fromExtensionManifest } from '../shared/settings'
20+
import { ecsTaskPermissionsUrl } from '../shared/constants'
2121

2222
interface EcsTaskIdentifer {
2323
readonly task: string
2424
readonly cluster: string
2525
readonly container: string
2626
}
2727

28-
const permissionsDocumentation = vscode.Uri.parse(
29-
'https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html#ecs-exec-enabling-and-using',
30-
true
31-
)
32-
28+
/**
29+
* See also: https://github.com/aws-containers/amazon-ecs-exec-checker
30+
*/
3331
export async function checkPermissionsForSsm(
3432
client: IamClient,
3533
task: Pick<TaskDefinition, 'taskRoleArn'>
3634
): Promise<void | never> {
3735
if (!task.taskRoleArn) {
3836
throw new ToolkitError('Containers must have a task role ARN', {
3937
code: 'NoTaskRoleArn',
40-
documentationUri: permissionsDocumentation,
38+
documentationUri: ecsTaskPermissionsUrl,
4139
})
4240
}
4341

42+
// https://github.com/aws-containers/amazon-ecs-exec-checker/blob/b1d163bd95c5b6f915e2bb3ad810e6f2aecae985/check-ecs-exec.sh#L536-L539
4443
const deniedActions = await client.getDeniedActions({
4544
PolicySourceArn: task.taskRoleArn,
4645
ActionNames: [
@@ -52,14 +51,18 @@ export async function checkPermissionsForSsm(
5251
})
5352

5453
if (deniedActions.length !== 0) {
54+
const deniedMsg = deniedActions.map(o => o.EvalActionName).join(', ')
5555
const message = localize(
5656
'AWS.command.ecs.runCommandInContainer.missingPermissions',
57-
'Insufficient permissions to execute command. Configure a task role as described in the documentation.'
57+
'Insufficient permissions to execute command, ensure the [task role is configured]({0}). Task role {1} is not authorized to perform: {2}',
58+
ecsTaskPermissionsUrl.toString(),
59+
task.taskRoleArn,
60+
deniedMsg
5861
)
5962

6063
throw new ToolkitError(message, {
6164
code: 'MissingPermissions',
62-
documentationUri: permissionsDocumentation,
65+
documentationUri: ecsTaskPermissionsUrl,
6366
details: { deniedActions: deniedActions.map(a => a.EvalActionName) },
6467
})
6568
}

src/shared/constants.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,12 @@ export const debugNewSamAppUrl: string = isCloud9()
101101
export const ecsDocumentationUrl: string = 'https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html'
102102
export const ecsExecToolkitGuideUrl: string =
103103
'https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/ecs-exec.html'
104-
export const ecsRequiredTaskPermissionsUrl: string =
104+
export const ecsTaskPermissionsUrl = vscode.Uri.parse(
105105
'https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html#ecs-exec-enabling-and-using'
106-
export const ecsRequiredIamPermissionsUrl: string =
106+
)
107+
export const ecsIamPermissionsUrl = vscode.Uri.parse(
107108
'https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html#ecs-exec-best-practices-limit-access-execute-command'
109+
)
108110

109111
/**
110112
* Moment format for rendering readable dates.

0 commit comments

Comments
 (0)