@@ -8,7 +8,6 @@ import globals from '../shared/extensionGlobals'
8
8
import * as nls from 'vscode-nls'
9
9
const localize = nls . loadMessageBundle ( )
10
10
11
- import * as vscode from 'vscode'
12
11
import { EcsClient } from '../shared/clients/ecsClient'
13
12
import { IamClient } from '../shared/clients/iamClient'
14
13
import { ToolkitError } from '../shared/errors'
@@ -18,29 +17,29 @@ import { TaskDefinition } from 'aws-sdk/clients/ecs'
18
17
import { getLogger } from '../shared/logger'
19
18
import { SSM } from 'aws-sdk'
20
19
import { fromExtensionManifest } from '../shared/settings'
20
+ import { ecsTaskPermissionsUrl } from '../shared/constants'
21
21
22
22
interface EcsTaskIdentifer {
23
23
readonly task : string
24
24
readonly cluster : string
25
25
readonly container : string
26
26
}
27
27
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
+ */
33
31
export async function checkPermissionsForSsm (
34
32
client : IamClient ,
35
33
task : Pick < TaskDefinition , 'taskRoleArn' >
36
34
) : Promise < void | never > {
37
35
if ( ! task . taskRoleArn ) {
38
36
throw new ToolkitError ( 'Containers must have a task role ARN' , {
39
37
code : 'NoTaskRoleArn' ,
40
- documentationUri : permissionsDocumentation ,
38
+ documentationUri : ecsTaskPermissionsUrl ,
41
39
} )
42
40
}
43
41
42
+ // https://github.com/aws-containers/amazon-ecs-exec-checker/blob/b1d163bd95c5b6f915e2bb3ad810e6f2aecae985/check-ecs-exec.sh#L536-L539
44
43
const deniedActions = await client . getDeniedActions ( {
45
44
PolicySourceArn : task . taskRoleArn ,
46
45
ActionNames : [
@@ -52,14 +51,18 @@ export async function checkPermissionsForSsm(
52
51
} )
53
52
54
53
if ( deniedActions . length !== 0 ) {
54
+ const deniedMsg = deniedActions . map ( o => o . EvalActionName ) . join ( ', ' )
55
55
const message = localize (
56
56
'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
58
61
)
59
62
60
63
throw new ToolkitError ( message , {
61
64
code : 'MissingPermissions' ,
62
- documentationUri : permissionsDocumentation ,
65
+ documentationUri : ecsTaskPermissionsUrl ,
63
66
details : { deniedActions : deniedActions . map ( a => a . EvalActionName ) } ,
64
67
} )
65
68
}
0 commit comments