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

Move codefresh and buildkite to ci-provider identity #1743

Merged
merged 7 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
23 changes: 21 additions & 2 deletions config/identity/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
define:
- &github-type "github-workflow"
- &gitlab-type "gitlab-pipeline"
- &codefresh-type "codefresh-workflow"
- &buildkite-type "buildkite-job"
oidc-issuers:
https://accounts.google.com:
issuer-url: https://accounts.google.com
Expand All @@ -25,7 +27,8 @@ oidc-issuers:
https://agent.buildkite.com:
issuer-url: https://agent.buildkite.com
client-id: sigstore
type: buildkite-job
type: ci-provider
ci-provider: *buildkite-type
contact: [email protected]
description: "Buildkite Agent OIDC tokens for job identity"
https://allow.pub:
Expand Down Expand Up @@ -84,7 +87,8 @@ oidc-issuers:
https://oidc.codefresh.io:
issuer-url: https://oidc.codefresh.io
client-id: sigstore
type: codefresh-workflow
type: ci-provider
ci-provider: *codefresh-type
contact: [email protected]
description: "Codefresh OIDC tokens for job identity"
https://ops.gitlab.net:
Expand Down Expand Up @@ -162,3 +166,18 @@ ci-issuer-metadata:
run-invocation-uri: "{{ .url }}/{{ .project_path }}/-/jobs/{{ .job_id }}"
source-repository-visibility-at-signing: "repository_visibility"
subject-alternative-name-template: "https://{{ .ci_config_ref_uri }}"
*codefresh-type:
default-template-values:
url: "https://g.codefresh.io"
extension-templates:
build-signer-uri: "{{if .platform_url}}{{.platform_ur}}{{ else }}{{.url}}{{end}}/build/{{ .workflow_id }}"
javanlacerda marked this conversation as resolved.
Show resolved Hide resolved
javanlacerda marked this conversation as resolved.
Show resolved Hide resolved
javanlacerda marked this conversation as resolved.
Show resolved Hide resolved
runner-environment: "runner_environment"
source-repository-uri: "scm_repo_url"
source-repository-ref: "scm_ref"
build-config-uri: "{{if .platform_url}}{{.platform_ur}}{{ else }}{{.url}}{{end}}/api/pipelines/{{ .pipeline_id }}"
run-invocation-uri: "{{if .platform_url}}{{.platform_ur}}{{ else }}{{.url}}{{end}}/build/{{ .workflow_id }}"
subject-alternative-name-template: "{{if .platform_url}}{{.platform_ur}}{{ else }}{{.url}}{{end}}/{{.account_name}}/{{.pipeline_name}}:{{.account_id}}/{{.pipeline_id}}"
*buildkite-type:
default-template-values:
url: "https://buildkite.com"
subject-alternative-name-template: "{{.url}}/{{.organization_slug}}/{{.pipeline_slug}}"
2 changes: 1 addition & 1 deletion docs/oidc.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ To add a new OIDC issuer:

* Add the new issuer to the [configuration](https://github.com/sigstore/fulcio/blob/main/config/identity/config.yaml).
* Attention: If your issuer is for a CI provider, you should set the `type` as `ci-provider` and set the field `ci-provider` with the name of your provider. You should also fill the `ci-issuer-metadata` with the `default-template-values`, `extension-templates` and `subject-alternative-name-template`, following the pattern defined on the example ([example](tbd after migrating the github to ci-provider)).
* Important notes: The `extension-templates` and the `subject-alternative-name-template` follows the templates [pattern](https://pkg.go.dev/text/template). The name used to fill the `ci-provider` field has to be the same used as key for `ci-issuer-metadata`, we suggest to use a variable for this.
* Important notes: The `extension-templates` and the `subject-alternative-name-template` follows the templates [pattern](https://pkg.go.dev/text/template). The name used to fill the `ci-provider` field has to be the same used as key for `ci-issuer-metadata`, we suggest to use a variable for this. If you set a `default-template-value` with the same name of a claim key, the default value will have priority over the claimed one.
* If your issuer is not for a CI provider, you need to follow the next steps:
* Add the new issuer to the [`identity` folder](https://github.com/sigstore/fulcio/tree/main/pkg/identity) ([example](https://github.com/sigstore/fulcio/tree/main/pkg/identity/email)). You will define an `Issuer` type and a way to map the token to the certificate extensions.
* Define a constant with the issuer type name in the [configuration](https://github.com/sigstore/fulcio/blob/afeadb3b7d11f704489637cabc4e150dea3e00ed/pkg/config/config.go#L213-L221), add update the [tests](https://github.com/sigstore/fulcio/blob/afeadb3b7d11f704489637cabc4e150dea3e00ed/pkg/config/config_test.go#L473-L503)
Expand Down
4 changes: 2 additions & 2 deletions pkg/identity/ciprovider/principal.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func applyTemplateOrReplace(extValueTemplate string, tokenClaims map[string]stri
var doc bytes.Buffer
// This option forces to having the claim that is required
// for the template
t := template.New("").Option("missingkey=error")
t := template.New("").Option("missingkey=zero")
javanlacerda marked this conversation as resolved.
Show resolved Hide resolved
// It shouldn't raise error since we already checked all
// templates in validateCIIssuerMetadata functions in config.go
p, err := t.Parse(extValueTemplate)
Expand All @@ -81,7 +81,7 @@ func applyTemplateOrReplace(extValueTemplate string, tokenClaims map[string]stri
}
claimValue, ok := mergedData[extValueTemplate]
if !ok {
return "", fmt.Errorf("value <%s> not present in either claims or defaults", extValueTemplate)
return "", nil
}
return claimValue, nil
}
Expand Down
11 changes: 8 additions & 3 deletions pkg/identity/ciprovider/principal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,12 @@ func TestApplyTemplateOrReplace(t *testing.T) {
`Missing key for template`: {
Template: "{{ .foo }}",
ExpectedResult: "",
ExpectErr: true,
ExpectErr: false,
},
`Empty string`: {
Template: "",
ExpectedResult: "",
ExpectErr: true,
ExpectErr: false,
},
`Replaceable string`: {
Template: "job_workflow_ref",
Expand All @@ -271,7 +271,7 @@ func TestApplyTemplateOrReplace(t *testing.T) {
`Missing string`: {
Template: "bar",
ExpectedResult: "",
ExpectErr: true,
ExpectErr: false,
},
`If else template`: {
Template: `refs/{{if eq .ref_type "branch"}}heads/{{ else }}tags/{{end}}{{ .ref_gitlab }}`,
Expand All @@ -283,6 +283,11 @@ func TestApplyTemplateOrReplace(t *testing.T) {
ExpectedResult: "refs/tags/1.0.0",
ExpectErr: false,
},
`Raise error for empty key in comparison`: {
Template: `{{if eq . ""}}foo{{else}}bar{{end}}`,
ExpectedResult: "",
ExpectErr: true,
},
}

for name, test := range tests {
Expand Down
Loading