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

Use API-level proto-to-id helper for audit fields #2692

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: 5 additions & 6 deletions pkg/server/api/entry/v1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/spiffe/go-spiffe/v2/spiffeid"
entryv1 "github.com/spiffe/spire-api-sdk/proto/spire/api/server/entry/v1"
"github.com/spiffe/spire-api-sdk/proto/spire/api/types"
"github.com/spiffe/spire/pkg/common/idutil"
"github.com/spiffe/spire/pkg/common/telemetry"
"github.com/spiffe/spire/pkg/server/api"
"github.com/spiffe/spire/pkg/server/api/rpccontext"
Expand Down Expand Up @@ -186,7 +185,7 @@ func (s *Service) BatchCreateEntry(ctx context.Context, req *entryv1.BatchCreate
r := s.createEntry(ctx, eachEntry, req.OutputMask)
results = append(results, r)
rpccontext.AuditRPCWithTypesStatus(ctx, r.Status, func() logrus.Fields {
return fieldsFromEntryProto(eachEntry, nil)
return fieldsFromEntryProto(ctx, eachEntry, nil)
})
}

Expand Down Expand Up @@ -241,7 +240,7 @@ func (s *Service) BatchUpdateEntry(ctx context.Context, req *entryv1.BatchUpdate
e := s.updateEntry(ctx, eachEntry, req.InputMask, req.OutputMask)
results = append(results, e)
rpccontext.AuditRPCWithTypesStatus(ctx, e.Status, func() logrus.Fields {
return fieldsFromEntryProto(eachEntry, req.InputMask)
return fieldsFromEntryProto(ctx, eachEntry, req.InputMask)
})
}

Expand Down Expand Up @@ -432,7 +431,7 @@ func (s *Service) updateEntry(ctx context.Context, e *types.Entry, inputMask *ty
}
}

func fieldsFromEntryProto(proto *types.Entry, inputMask *types.EntryMask) logrus.Fields {
func fieldsFromEntryProto(ctx context.Context, proto *types.Entry, inputMask *types.EntryMask) logrus.Fields {
fields := logrus.Fields{}

if proto == nil {
Expand All @@ -444,14 +443,14 @@ func fieldsFromEntryProto(proto *types.Entry, inputMask *types.EntryMask) logrus
}

if (inputMask == nil || inputMask.SpiffeId) && proto.SpiffeId != nil {
id, err := idutil.IDFromProto(proto.SpiffeId)
id, err := api.IDFromProto(ctx, proto.SpiffeId)
if err == nil {
fields[telemetry.SPIFFEID] = id.String()
}
}

if (inputMask == nil || inputMask.ParentId) && proto.ParentId != nil {
id, err := idutil.IDFromProto(proto.ParentId)
id, err := api.IDFromProto(ctx, proto.ParentId)
if err == nil {
fields[telemetry.ParentID] = id.String()
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/server/api/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
)

func TrustDomainMemberIDFromProto(ctx context.Context, td spiffeid.TrustDomain, protoID *types.SPIFFEID) (spiffeid.ID, error) {
id, err := idFromProto(ctx, protoID)
id, err := IDFromProto(ctx, protoID)
if err != nil {
return spiffeid.ID{}, err
}
Expand All @@ -40,7 +40,7 @@ func VerifyTrustDomainMemberID(td spiffeid.TrustDomain, id spiffeid.ID) error {
}

func TrustDomainAgentIDFromProto(ctx context.Context, td spiffeid.TrustDomain, protoID *types.SPIFFEID) (spiffeid.ID, error) {
id, err := idFromProto(ctx, protoID)
id, err := IDFromProto(ctx, protoID)
if err != nil {
return spiffeid.ID{}, err
}
Expand All @@ -64,7 +64,7 @@ func VerifyTrustDomainAgentID(td spiffeid.TrustDomain, id spiffeid.ID) error {
}

func TrustDomainWorkloadIDFromProto(ctx context.Context, td spiffeid.TrustDomain, protoID *types.SPIFFEID) (spiffeid.ID, error) {
id, err := idFromProto(ctx, protoID)
id, err := IDFromProto(ctx, protoID)
if err != nil {
return spiffeid.ID{}, err
}
Expand Down Expand Up @@ -103,7 +103,8 @@ func RemoveEnsureLeadingSlashLogLimit() {
ensureLeadingSlashLogLimiter.SetLimit(rate.Inf)
}

func idFromProto(ctx context.Context, protoID *types.SPIFFEID) (spiffeid.ID, error) {
// IDFromProto converts a SPIFFEID message into an ID type
func IDFromProto(ctx context.Context, protoID *types.SPIFFEID) (spiffeid.ID, error) {
if protoID == nil {
return spiffeid.ID{}, errors.New("request must specify SPIFFE ID")
}
Expand Down