-
Notifications
You must be signed in to change notification settings - Fork 546
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
Support Gitpod workspaces #3601
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// Copyright 2021 The Sigstore Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package gitpod defines an implementation of the providers.Interface | ||
// that reads identity tokens from the gitpod API within a workspace. | ||
package gitpod |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,72 @@ | ||||||
// | ||||||
// Copyright 2021 The Sigstore Authors. | ||||||
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.
Suggested change
|
||||||
// | ||||||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
// you may not use this file except in compliance with the License. | ||||||
// You may obtain a copy of the License at | ||||||
// | ||||||
// http://www.apache.org/licenses/LICENSE-2.0 | ||||||
// | ||||||
// Unless required by applicable law or agreed to in writing, software | ||||||
// distributed under the License is distributed on an "AS IS" BASIS, | ||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
// See the License for the specific language governing permissions and | ||||||
// limitations under the License. | ||||||
|
||||||
package gitpod | ||||||
|
||||||
import ( | ||||||
"bytes" | ||||||
"context" | ||||||
"encoding/json" | ||||||
"os/exec" | ||||||
|
||||||
"github.com/sigstore/cosign/v2/pkg/cosign/env" | ||||||
"github.com/sigstore/cosign/v2/pkg/providers" | ||||||
) | ||||||
|
||||||
func init() { | ||||||
providers.Register("filesystem", &gitpod{}) | ||||||
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.
Suggested change
|
||||||
} | ||||||
|
||||||
type gitpod struct{} | ||||||
|
||||||
var _ providers.Interface = (*gitpod)(nil) | ||||||
|
||||||
// Enabled implements providers.Interface | ||||||
func (ga *gitpod) Enabled(_ context.Context) bool { | ||||||
// Check we are in a Gitpod Workspace | ||||||
if env.Getenv(env.VariableGitpodWorkspaceId) != "" { | ||||||
|
||||||
//Check we are able to generate tokens with a verified email address | ||||||
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.
Suggested change
( |
||||||
output, err := exec.Command("gp", "idp", "token", "--audience", "example.org", "--decode").Output() | ||||||
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. How necessary is this check, if the workspace variable is known to be set? The github provider, for example, only bothers to check the variable. Is there a timeout option for this command? All the providers are looped through when a new signer is created, so if this command doesn't exit quickly when not enabled, it will stall keyless signing. |
||||||
if err != nil { | ||||||
return false | ||||||
} | ||||||
|
||||||
var token struct { | ||||||
Payload *struct { | ||||||
Email *string `json:"email"` | ||||||
EmailVerified bool `json:"email_verified"` | ||||||
} `json:"Payload"` | ||||||
} | ||||||
dec := json.NewDecoder(bytes.NewBuffer(output)) | ||||||
if err := dec.Decode(&token); err != nil { | ||||||
return false | ||||||
} | ||||||
|
||||||
if token.Payload != nil { | ||||||
return token.Payload.Email != nil && token.Payload.EmailVerified | ||||||
} | ||||||
} | ||||||
return false | ||||||
} | ||||||
|
||||||
// Provide implements providers.Interface | ||||||
func (ga *gitpod) Provide(ctx context.Context, audience string) (string, error) { | ||||||
token, err := exec.Command("gp", "idp", "token", "--audience", audience).Output() | ||||||
if err != nil { | ||||||
return "", err | ||||||
} | ||||||
return string(token), nil | ||||||
} |
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.