Skip to content
Open
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
15 changes: 15 additions & 0 deletions pkg/server/api/agent/v1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"crypto/x509"
"errors"
"fmt"
"net/url"
"strings"
"time"

"github.com/andres-erbsen/clock"
Expand Down Expand Up @@ -695,6 +697,19 @@ func (s *Service) attestChallengeResponse(ctx context.Context, agentStream agent
st := status.Convert(err)
return nil, api.MakeErr(log, st.Code(), st.Message(), nil)
}
if result.AgentID != "" {
parsedId, err := url.Parse(result.AgentID)
if err == nil {
path := parsedId.Path
trimmedPath := strings.TrimPrefix(path, "/")
if trimmedPath != "" {
result.Selectors = append(result.Selectors, &common.Selector{
Type: "spiffe",
Value: fmt.Sprintf("svid:%s", trimmedPath),
})
}
}
}
return result, nil
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/server/api/agent/v1/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2718,6 +2718,7 @@ func TestAttestAgent(t *testing.T) {
request: getAttestAgentRequest("test_type", []byte("payload_with_result"), testCsr),
expectedID: spiffeid.RequireFromPath(td, "/spire/agent/test_type/id_with_result"),
expectedSelectors: []*common.Selector{
{Type: "spiffe", Value: "svid:spire/agent/test_type/id_with_result"},
{Type: "test_type", Value: "result"},
},
expectLogs: []spiretest.LogEntry{
Expand Down Expand Up @@ -2749,6 +2750,7 @@ func TestAttestAgent(t *testing.T) {
request: getAttestAgentRequest("test_type", []byte("payload_with_result"), testCsr),
expectedID: spiffeid.RequireFromPath(td, "/spire/agent/test_type/id_with_result"),
expectedSelectors: []*common.Selector{
{Type: "spiffe", Value: "svid:spire/agent/test_type/id_with_result"},
{Type: "test_type", Value: "result"},
},
expectLogs: []spiretest.LogEntry{
Expand Down Expand Up @@ -2798,6 +2800,7 @@ func TestAttestAgent(t *testing.T) {
request: getAttestAgentRequest("test_type", []byte("payload_with_challenge"), testCsr),
expectedID: spiffeid.RequireFromPath(td, "/spire/agent/test_type/id_with_challenge"),
expectedSelectors: []*common.Selector{
{Type: "spiffe", Value: "svid:spire/agent/test_type/id_with_challenge"},
{Type: "test_type", Value: "challenge"},
},
expectLogs: []spiretest.LogEntry{
Expand Down Expand Up @@ -2828,6 +2831,7 @@ func TestAttestAgent(t *testing.T) {
request: getAttestAgentRequest("test_type", []byte("payload_attested_before"), testCsr),
expectedID: spiffeid.RequireFromPath(td, "/spire/agent/test_type/id_attested_before"),
expectedSelectors: []*common.Selector{
{Type: "spiffe", Value: "svid:spire/agent/test_type/id_attested_before"},
{Type: "test_type", Value: "attested_before"},
},
expectedVersion: "1.2.3",
Expand Down Expand Up @@ -3178,6 +3182,9 @@ func TestAttestAgent(t *testing.T) {
name: "nodeattestor returns ID outside of its namespace",
request: getAttestAgentRequest("test_type", []byte("payload_return_id_outside_namespace"), testCsr),
expectedID: spiffeid.RequireFromPath(td, "/id_outside_namespace"),
expectedSelectors: []*common.Selector{
{Type: "spiffe", Value: "svid:id_outside_namespace"},
},
expectLogs: []spiretest.LogEntry{
{
Level: logrus.WarnLevel,
Expand Down Expand Up @@ -3214,6 +3221,7 @@ func TestAttestAgent(t *testing.T) {
request: getAttestAgentRequest("test_type", []byte("payload_selector_dups"), testCsr),
expectedID: spiffeid.RequireFromPath(td, "/spire/agent/test_type/id_selector_dups"),
expectedSelectors: []*common.Selector{
{Type: "spiffe", Value: "svid:spire/agent/test_type/id_selector_dups"},
{Type: "test_type", Value: "A"},
{Type: "test_type", Value: "B"},
{Type: "test_type", Value: "C"},
Expand Down
Loading