Skip to content
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
5 changes: 5 additions & 0 deletions tool/tsh/common/workload_identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ func (c *issueX509Command) run(cf *CLIConf) error {
)
}

// Create directory if it does not exist.
if err := os.MkdirAll(c.outputDirectory, teleport.PrivateDirMode); err != nil {
return trace.Wrap(err, "creating output directory")
}

// Write private key
privBytes, err := x509.MarshalPKCS8PrivateKey(privateKey)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions tool/tsh/common/workload_identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,22 @@ func TestWorkloadIdentityIssueX509(t *testing.T) {
}, time.Second*5, 100*time.Millisecond)

homeDir, _ := mustLoginLegacy(t, s)
temp := t.TempDir()
outDir := filepath.Join(t.TempDir(), "out")
err = Run(
ctx,
[]string{
"workload-identity",
"issue-x509",
"--insecure",
"--output", temp,
"--output", outDir,
"--credential-ttl", "10m",
"--name-selector", "my-workload-identity",
},
setHomePath(homeDir),
)
require.NoError(t, err)

certPEM, err := os.ReadFile(filepath.Join(temp, "svid.pem"))
certPEM, err := os.ReadFile(filepath.Join(outDir, "svid.pem"))
require.NoError(t, err)
certs, err := tlsca.ParseCertificatePEMs(certPEM)
require.NoError(t, err)
Expand All @@ -114,7 +114,7 @@ func TestWorkloadIdentityIssueX509(t *testing.T) {
// Sanity check we generated an ECDSA public key (test suite uses
// balanced-v1 algorithm suite).
require.IsType(t, (*ecdsa.PublicKey)(nil), certs[0].PublicKey)
keyPEM, err := os.ReadFile(filepath.Join(temp, "svid_key.pem"))
keyPEM, err := os.ReadFile(filepath.Join(outDir, "svid_key.pem"))
require.NoError(t, err)
keyBlock, _ := pem.Decode(keyPEM)
privateKey, err := x509.ParsePKCS8PrivateKey(keyBlock.Bytes)
Expand All @@ -123,7 +123,7 @@ func TestWorkloadIdentityIssueX509(t *testing.T) {
require.Implements(t, (*crypto.Signer)(nil), privateKey)
require.Equal(t, certs[0].PublicKey, privateKey.(crypto.Signer).Public())

bundlePEM, err := os.ReadFile(filepath.Join(temp, "svid_bundle.pem"))
bundlePEM, err := os.ReadFile(filepath.Join(outDir, "svid_bundle.pem"))
require.NoError(t, err)
bundleBlock, _ := pem.Decode(bundlePEM)
_, err = x509.ParseCertificate(bundleBlock.Bytes)
Expand Down
Loading