- 
                Notifications
    You must be signed in to change notification settings 
- Fork 183
Added multi-role guide #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            micahhausler
  wants to merge
  1
  commit into
  aws:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
micahhausler:role-guidelines
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or 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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -85,7 +85,7 @@ This webhook is for mutating pods that will require AWS IAM access. | |
| expirationSeconds: 86400 | ||
| path: token | ||
| ``` | ||
|  | ||
| ### Usage with Windows container workloads | ||
|  | ||
| To ensure workloads are scheduled on windows nodes have the right environment variables, they must have a `nodeSelector` targeting windows it must run on. Workloads targeting windows nodes using `nodeAffinity` are currently not supported. | ||
|  | @@ -170,6 +170,124 @@ TODO | |
| ## Development | ||
| TODO | ||
|  | ||
| ## Guides | ||
|  | ||
| ### Different roles in the same pod | ||
|  | ||
| You can use different IAM roles in different containers within the same pod, but | ||
| there is additional setup and configuration that you'll have to modify your pod | ||
| spec by adding the volumes and environment variables without the help of this | ||
| webhook. | ||
|  | ||
| The way this works is by using different client IDs (also known as audience) in | ||
| different tokens. Below is an example pod, but you'll probably use this on a | ||
| Deployment, Daemonset, or some other controller type. | ||
|  | ||
| First, you'll need to modify your IAM OIDC Identity Provider (IDP) to add an | ||
| additional audience/client ID. In this example, the IDP will use the audiences | ||
| `sts.amazonaws.com` and `some-other-client-id-arbitrary-string`. | ||
|  | ||
| **Note**: _Containers in a pod share a common kernel, and containers are not a | ||
| hard security boundary. Using different AWS IAM roles for containers in the same | ||
| pod can be used to reduce unnecesary permissions and to reduce the blast-radius | ||
| of misconfiguration, but should not be relied on to segment untrusted code in | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/segment/isolate/ | ||
| running in a container._ | ||
|  | ||
| ```yaml | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: my-pod | ||
| namespace: default | ||
| spec: | ||
| serviceAccountName: my-serviceaccount | ||
| containers: | ||
| - name: container1 | ||
| image: container-image1 | ||
| env: | ||
| - name: AWS_ROLE_ARN | ||
| value: "arn:aws:iam::111122223333:role/role-1" | ||
| - name: AWS_WEB_IDENTITY_TOKEN_FILE | ||
| value: "/var/run/secrets/eks.amazonaws.com/serviceaccount/token" | ||
| volumeMounts: | ||
| - mountPath: "/var/run/secrets/eks.amazonaws.com/serviceaccount/" | ||
| name: aws-token-1 | ||
| - name: container2 | ||
| image: container-image2 | ||
| env: | ||
| - name: AWS_ROLE_ARN | ||
| value: "arn:aws:iam::111122223333:role/role-2" | ||
| - name: AWS_WEB_IDENTITY_TOKEN_FILE | ||
| value: "/var/run/secrets/eks.amazonaws.com/serviceaccount/token" | ||
| volumeMounts: | ||
| - mountPath: "/var/run/secrets/eks.amazonaws.com/serviceaccount/" | ||
| name: aws-token-2 | ||
| volumes: | ||
| - name: aws-token-1 | ||
| projected: | ||
| sources: | ||
| - serviceAccountToken: | ||
| audience: "sts.amazonaws.com" | ||
| expirationSeconds: 86400 | ||
| path: token | ||
| - name: aws-token-2 | ||
| projected: | ||
| sources: | ||
| - serviceAccountToken: | ||
| audience: "some-other-client-id-arbitrary-string" | ||
| expirationSeconds: 86400 | ||
| path: token | ||
| ``` | ||
|  | ||
| Now for each role, you'll need to add a key to the `StringEquals` condition map | ||
| in the role's trust policy specifying the proper audience (`aud`) for each role. | ||
|  | ||
| `role-1` trust policy: | ||
|  | ||
| ```json | ||
| { | ||
| "Version": "2012-10-17", | ||
| "Statement": [ | ||
| { | ||
| "Effect": "Allow", | ||
| "Principal": { | ||
| "Federated": "arn:aws:iam::ACCOUNT_ID:oidc-provider/oidc.REGION.eks.amazonaws.com/CLUSTER_ID" | ||
| }, | ||
| "Action": "sts:AssumeRoleWithWebIdentity", | ||
| "Condition": { | ||
| "StringEquals": { | ||
| "oidc.REGION.eks.amazonaws.com/CLUSTER_ID:sub": "system:serviceaccount:default:my-serviceaccount", | ||
| "oidc.REGION.eks.amazonaws.com/CLUSTER_ID:aud": "sts.amazonaws.com" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|  | ||
| And `role-2` trust policy: | ||
|  | ||
| ```json | ||
| { | ||
| "Version": "2012-10-17", | ||
| "Statement": [ | ||
| { | ||
| "Effect": "Allow", | ||
| "Principal": { | ||
| "Federated": "arn:aws:iam::ACCOUNT_ID:oidc-provider/oidc.REGION.eks.amazonaws.com/CLUSTER_ID" | ||
| }, | ||
| "Action": "sts:AssumeRoleWithWebIdentity", | ||
| "Condition": { | ||
| "StringEquals": { | ||
| "oidc.REGION.eks.amazonaws.com/CLUSTER_ID:sub": "system:serviceaccount:default:my-serviceaccount", | ||
| "oidc.REGION.eks.amazonaws.com/CLUSTER_ID:aud": "some-other-client-id-arbitrary-string" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|  | ||
| ## Code of Conduct | ||
| See [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) | ||
|  | ||
|  | ||
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is additional setup and configuration and you'll have to modify your pod