Skip to content

Instantly share code, notes, and snippets.

@jaxley
Last active February 13, 2019 00:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaxley/509ca884d084a1a5f7daad90fe36ecd6 to your computer and use it in GitHub Desktop.
Save jaxley/509ca884d084a1a5f7daad90fe36ecd6 to your computer and use it in GitHub Desktop.
Iterate all AWS ECS task families and identify any tasks with a 'privileged' container flag set
#!/usr/bin/env python
import boto3
import pprint
import sys
sys.stdout.flush()
# to support AWS profiles, just change the profile name here. Be sure you've set the region in that profile config
devSession = boto3.session.Session(profile_name='default')
client = devSession.client('ecs')
paginator = client.get_paginator('list_task_definition_families')
pages = paginator.paginate(
status='ACTIVE',
maxResults=100
)
for page in pages:
for family in page['families']:
response = client.describe_task_definition(
taskDefinition=family
)
latestTaskFamily="{}:{}".format(family,response['taskDefinition']['revision'])
for containerDef in response['taskDefinition']['containerDefinitions']:
if 'privileged' in containerDef:
print "PRIVILEGED: {}; {} => {}".format(containerDef['privileged'], latestTaskFamily, containerDef['name'])
@jaxley
Copy link
Author

jaxley commented Feb 12, 2019

If you have your AWS credentials set up in ~/.aws/credentials, then this script will iterate all of the ECS task families and list out any that have a non-null 'privileged' flag. It will list the specific task family and container definition that has this flag set.

Useful for identifying where you have privileged (root-level) containers running.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment