Skip to content

Commit 638b39a

Browse files
guilhermoccd-goro
authored andcommitted
Add hint field delegated identity API (spiffe#4074)
Add hint field delegated identity API Signed-off-by: Guilherme Carvalho <[email protected]> Signed-off-by: Dmitry Gorochovsky <[email protected]>
1 parent cabbc84 commit 638b39a

File tree

5 files changed

+138
-71
lines changed

5 files changed

+138
-71
lines changed

cmd/spire-server/cli/jwt/mint_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ func TestMintRun(t *testing.T) {
202202
"path": "/workload"
203203
},
204204
"expires_at": "1628600000",
205+
"hint": "",
205206
"issued_at": "1628500000"
206207
}
207208
}`, token)},
@@ -244,6 +245,7 @@ func TestMintRun(t *testing.T) {
244245
"svid": {
245246
"token": "malformed token",
246247
"expires_at": "0",
248+
"hint": "",
247249
"issued_at": "0"
248250
}
249251
}`,
@@ -278,6 +280,7 @@ func TestMintRun(t *testing.T) {
278280
"path": "/workload"
279281
},
280282
"expires_at": "1628500000",
283+
"hint": "",
281284
"issued_at": "1628600000"
282285
}
283286
}`, expiredToken),

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ require (
5959
github.com/sigstore/sigstore v1.5.2
6060
github.com/sirupsen/logrus v1.9.0
6161
github.com/spiffe/go-spiffe/v2 v2.1.4
62-
github.com/spiffe/spire-api-sdk v1.2.5-0.20230315170933-494fe186be48
62+
github.com/spiffe/spire-api-sdk v1.2.5-0.20230413135745-699e242b965d
6363
github.com/spiffe/spire-plugin-sdk v1.4.4-0.20230203133000-75d7213a0ba0
6464
github.com/stretchr/testify v1.8.2
6565
github.com/uber-go/tally/v4 v4.1.7

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,8 +2027,8 @@ github.com/spf13/viper v1.13.0 h1:BWSJ/M+f+3nmdz9bxB+bWX28kkALN2ok11D0rSo8EJU=
20272027
github.com/spf13/viper v1.13.0/go.mod h1:Icm2xNL3/8uyh/wFuB1jI7TiTNKp8632Nwegu+zgdYw=
20282028
github.com/spiffe/go-spiffe/v2 v2.1.4 h1:Z31Ycaf2Z5DF38sQGmp+iGKjBhBlSzfAq68bfy67Mxw=
20292029
github.com/spiffe/go-spiffe/v2 v2.1.4/go.mod h1:eVDqm9xFvyqao6C+eQensb9ZPkyNEeaUbqbBpOhBnNk=
2030-
github.com/spiffe/spire-api-sdk v1.2.5-0.20230315170933-494fe186be48 h1:jRrlbqir48TQ4yMupNf9I1/OMrVTK0myhWxwOYqiS0g=
2031-
github.com/spiffe/spire-api-sdk v1.2.5-0.20230315170933-494fe186be48/go.mod h1:4uuhFlN6KBWjACRP3xXwrOTNnvaLp1zJs8Lribtr4fI=
2030+
github.com/spiffe/spire-api-sdk v1.2.5-0.20230413135745-699e242b965d h1:0etgpf2R3yE+dwCM+leo1OcayEXfBdv0nZ3I7k/iRmk=
2031+
github.com/spiffe/spire-api-sdk v1.2.5-0.20230413135745-699e242b965d/go.mod h1:4uuhFlN6KBWjACRP3xXwrOTNnvaLp1zJs8Lribtr4fI=
20322032
github.com/spiffe/spire-plugin-sdk v1.4.4-0.20230203133000-75d7213a0ba0 h1:+ETVN721ZSZvi8CmR0oGf2KRSIkVMvWC8PqON9IknrM=
20332033
github.com/spiffe/spire-plugin-sdk v1.4.4-0.20230203133000-75d7213a0ba0/go.mod h1:4KW5J6abGIAyUS8IL7Fi0NOfoWR6jA5LufKPnIdm9FE=
20342034
github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI=

pkg/agent/api/delegatedidentity/v1/service.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ func composeX509SVIDBySelectors(update *cache.WorkloadUpdate) (*delegatedidentit
196196
Id: id,
197197
CertChain: x509util.RawCertsFromCertificates(identity.SVID),
198198
ExpiresAt: identity.SVID[0].NotAfter.Unix(),
199+
Hint: identity.Entry.Hint,
199200
},
200201
X509SvidKey: keyData,
201202
}
@@ -270,7 +271,8 @@ func (s *Service) FetchJWTSVIDs(ctx context.Context, req *delegatedidentityv1.Fe
270271
log.WithError(err).Error("Invalid argument; could not parse provided selectors")
271272
return nil, status.Error(codes.InvalidArgument, "could not parse provided selectors")
272273
}
273-
var spiffeIDs []spiffeid.ID
274+
275+
resp = new(delegatedidentityv1.FetchJWTSVIDsResponse)
274276

275277
entries := s.manager.MatchingRegistrationEntries(selectors)
276278
for _, entry := range entries {
@@ -280,38 +282,34 @@ func (s *Service) FetchJWTSVIDs(ctx context.Context, req *delegatedidentityv1.Fe
280282
return nil, status.Errorf(codes.InvalidArgument, "invalid requested SPIFFE ID: %v", err)
281283
}
282284

283-
spiffeIDs = append(spiffeIDs, spiffeID)
284-
}
285-
286-
if len(spiffeIDs) == 0 {
287-
log.Error("No identity issued")
288-
return nil, status.Error(codes.PermissionDenied, "no identity issued")
289-
}
290-
291-
resp = new(delegatedidentityv1.FetchJWTSVIDsResponse)
292-
for _, id := range spiffeIDs {
293-
loopLog := log.WithField(telemetry.SPIFFEID, id.String())
285+
loopLog := log.WithField(telemetry.SPIFFEID, spiffeID.String())
294286

295287
var svid *client.JWTSVID
296-
svid, err = s.manager.FetchJWTSVID(ctx, id, req.Audience)
288+
svid, err = s.manager.FetchJWTSVID(ctx, spiffeID, req.Audience)
297289
if err != nil {
298290
loopLog.WithError(err).Error("Could not fetch JWT-SVID")
299291
return nil, status.Errorf(codes.Unavailable, "could not fetch JWT-SVID: %v", err)
300292
}
301293
resp.Svids = append(resp.Svids, &types.JWTSVID{
302294
Token: svid.Token,
303295
Id: &types.SPIFFEID{
304-
TrustDomain: id.TrustDomain().String(),
305-
Path: id.Path(),
296+
TrustDomain: spiffeID.TrustDomain().String(),
297+
Path: spiffeID.Path(),
306298
},
307299
ExpiresAt: svid.ExpiresAt.Unix(),
308300
IssuedAt: svid.IssuedAt.Unix(),
301+
Hint: entry.Hint,
309302
})
310303

311304
ttl := time.Until(svid.ExpiresAt)
312305
loopLog.WithField(telemetry.TTL, ttl.Seconds()).Debug("Fetched JWT SVID")
313306
}
314307

308+
if len(resp.Svids) == 0 {
309+
log.Error("No identity issued")
310+
return nil, status.Error(codes.PermissionDenied, "no identity issued")
311+
}
312+
315313
return resp, nil
316314
}
317315

0 commit comments

Comments
 (0)