Last active
February 13, 2019 00:02
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.