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

Export attestation token filepath and filename #333

Merged
merged 1 commit into from
Jul 14, 2023
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
11 changes: 6 additions & 5 deletions launcher/container_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ type ContainerRunner struct {
const (
// hostTokenPath defined the directory in the host that will store attestation tokens
hostTokenPath = "/tmp/container_launcher/"
// containerTokenMountPath defined the directory in the container stores attestation tokens
containerTokenMountPath = "/run/container_launcher/"
attestationVerifierTokenFile = "attestation_verifier_claims_token"
// ContainerTokenMountPath defined the directory in the container stores attestation tokens
ContainerTokenMountPath = "/run/container_launcher/"
// AttestationVerifierTokenFile defines the name of the file the attestation token is stored in.
AttestationVerifierTokenFile = "attestation_verifier_claims_token"
tokenFileTmp = ".token.tmp"
)

Expand Down Expand Up @@ -268,7 +269,7 @@ func formatEnvVars(envVars []spec.EnvVar) ([]string, error) {
// appendTokenMounts appends the default mount specs for the OIDC token
func appendTokenMounts(mounts []specs.Mount) []specs.Mount {
m := specs.Mount{}
m.Destination = containerTokenMountPath
m.Destination = ContainerTokenMountPath
m.Type = "bind"
m.Source = hostTokenPath
m.Options = []string{"rbind", "ro"}
Expand Down Expand Up @@ -365,7 +366,7 @@ func (r *ContainerRunner) refreshToken(ctx context.Context) (time.Duration, erro
}

// Rename the temp file to the token file (to avoid race conditions).
if err = os.Rename(tmpTokenPath, path.Join(hostTokenPath, attestationVerifierTokenFile)); err != nil {
if err = os.Rename(tmpTokenPath, path.Join(hostTokenPath, AttestationVerifierTokenFile)); err != nil {
return 0, fmt.Errorf("failed to rename the token file: %v", err)
}

Expand Down
10 changes: 5 additions & 5 deletions launcher/container_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestRefreshToken(t *testing.T) {
t.Fatalf("refreshToken returned with error: %v", err)
}

filepath := path.Join(hostTokenPath, attestationVerifierTokenFile)
filepath := path.Join(hostTokenPath, AttestationVerifierTokenFile)
data, err := os.ReadFile(filepath)
if err != nil {
t.Fatalf("Failed to read from %s: %v", filepath, err)
Expand Down Expand Up @@ -194,7 +194,7 @@ func TestFetchAndWriteTokenSucceeds(t *testing.T) {
t.Fatalf("fetchAndWriteToken failed: %v", err)
}

filepath := path.Join(hostTokenPath, attestationVerifierTokenFile)
filepath := path.Join(hostTokenPath, AttestationVerifierTokenFile)
data, err := os.ReadFile(filepath)
if err != nil {
t.Fatalf("Failed to read from %s: %v", filepath, err)
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestTokenIsNotChangedIfRefreshFails(t *testing.T) {
t.Fatalf("fetchAndWriteToken failed: %v", err)
}

filepath := path.Join(hostTokenPath, attestationVerifierTokenFile)
filepath := path.Join(hostTokenPath, AttestationVerifierTokenFile)
data, err := os.ReadFile(filepath)
if err != nil {
t.Fatalf("Failed to read from %s: %v", filepath, err)
Expand Down Expand Up @@ -306,7 +306,7 @@ func testRetryPolicyWithNTries(t *testing.T, numTries int, expectRefresh bool) {
if err := runner.fetchAndWriteTokenWithRetry(ctx, testRetryPolicyThreeTimes()); err != nil {
t.Fatalf("fetchAndWriteTokenWithRetry failed: %v", err)
}
filepath := path.Join(hostTokenPath, attestationVerifierTokenFile)
filepath := path.Join(hostTokenPath, AttestationVerifierTokenFile)
data, err := os.ReadFile(filepath)
if err != nil {
t.Fatalf("failed to read from %s: %v", filepath, err)
Expand Down Expand Up @@ -360,7 +360,7 @@ func TestFetchAndWriteTokenWithTokenRefresh(t *testing.T) {
t.Fatalf("fetchAndWriteToken failed: %v", err)
}

filepath := path.Join(hostTokenPath, attestationVerifierTokenFile)
filepath := path.Join(hostTokenPath, AttestationVerifierTokenFile)
data, err := os.ReadFile(filepath)
if err != nil {
t.Fatalf("Failed to read from %s: %v", filepath, err)
Expand Down