Skip to content
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

Extract additional claims from github-workflow token #306

Merged
merged 1 commit into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion OID_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ Note that all values begin from the root OID 1.3.6.1.4.1.57264 [registered by Da
- This contains the `event_name` claim from the GitHub OIDC Identity token that contains the name of the event that triggered the workflow run. [(docs)](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#understanding-the-oidc-token)
- *1.3.6.1.4.1.57264.1.3*: (GithubWorkflowSha)
- This contains the `sha` claim from the GitHub OIDC Identity token that contains the commit SHA that the workflow run was based upon. [(docs)](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#understanding-the-oidc-token)

- *1.3.6.1.4.1.57264.1.4*: (GithubWorkflowName)
- This contains the `workflow` claim from the GitHub OIDC Identity token that contains the name of the executed workflow. [(docs)](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#understanding-the-oidc-token)
- *1.3.6.1.4.1.57264.1.5*: (GithubWorkflowRepository)
- This contains the `repository` claim from the GitHub OIDC Identity token that contains the repository that the workflow run was based upon. [(docs)](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#understanding-the-oidc-token)
- *1.3.6.1.4.1.57264.1.6*: (GithubWorkflowRef)
- This contains the `ref` claim from the GitHub OIDC Identity token that contains the git ref that the workflow run was based upon. [(docs)](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#understanding-the-oidc-token)
21 changes: 21 additions & 0 deletions pkg/ca/x509ca/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,27 @@ func AdditionalExtensions(subject *challenges.ChallengeResult) []pkix.Extension
Value: []byte(sha),
})
}

if name, ok := subject.AdditionalInfo[challenges.GithubWorkflowName]; ok {
res = append(res, pkix.Extension{
Id: asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 57264, 1, 4},
Value: []byte(name),
})
}

if repo, ok := subject.AdditionalInfo[challenges.GithubWorkflowRepository]; ok {
res = append(res, pkix.Extension{
Id: asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 57264, 1, 5},
Value: []byte(repo),
})
}

if ref, ok := subject.AdditionalInfo[challenges.GithubWorkflowRef]; ok {
res = append(res, pkix.Extension{
Id: asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 57264, 1, 6},
Value: []byte(ref),
})
}
}
return res
}
Expand Down
17 changes: 13 additions & 4 deletions pkg/challenges/challenges.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ type AdditionalInfo int
const (
GithubWorkflowTrigger AdditionalInfo = iota
GithubWorkflowSha
GithubWorkflowName
GithubWorkflowRepository
GithubWorkflowRef
)

type ChallengeResult struct {
Expand Down Expand Up @@ -254,8 +257,11 @@ func workflowFromIDToken(token *oidc.IDToken) (string, error) {
func workflowInfoFromIDToken(token *oidc.IDToken) (map[AdditionalInfo]string, error) {
// Extract custom claims
var claims struct {
Sha string `json:"sha"`
Trigger string `json:"event_name"`
Sha string `json:"sha"`
Trigger string `json:"event_name"`
Repository string `json:"repository"`
Workflow string `json:"workflow"`
Ref string `json:"ref"`
// The other fields that are present here seem to depend on the type
// of workflow trigger that initiated the action.
}
Expand All @@ -265,8 +271,11 @@ func workflowInfoFromIDToken(token *oidc.IDToken) (map[AdditionalInfo]string, er

// We use this in URIs, so it has to be a URI.
return map[AdditionalInfo]string{
GithubWorkflowSha: claims.Sha,
GithubWorkflowTrigger: claims.Trigger}, nil
GithubWorkflowSha: claims.Sha,
GithubWorkflowTrigger: claims.Trigger,
GithubWorkflowName: claims.Workflow,
GithubWorkflowRepository: claims.Repository,
GithubWorkflowRef: claims.Ref}, nil
}

func isSpiffeIDAllowed(host, spiffeID string) bool {
Expand Down