Skip to content

Commit

Permalink
resolve some lints
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Yacob <[email protected]>
  • Loading branch information
MarcosDY committed Aug 11, 2024
1 parent 4da4c4c commit fc7b2b4
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 40 deletions.
2 changes: 1 addition & 1 deletion pkg/common/telemetry/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ const (
Subject = "subject"

// Subject tags a certificate subject key ID
SubjectKeyId = "subject_key_id"
SubjectKeyID = "subject_key_id"

// SVIDMapSize is the gauge key for the size of the LRU cache SVID map
SVIDMapSize = "lru_cache_svid_map_size"
Expand Down
7 changes: 3 additions & 4 deletions pkg/server/api/localauthority/v1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ func (s *Service) TaintX509UpstreamAuthority(ctx context.Context, req *localauth
log := rpccontext.Logger(ctx)

if req.SubjectKeyId != "" {
log = log.WithField(telemetry.SubjectKeyId, req.SubjectKeyId)
log = log.WithField(telemetry.SubjectKeyID, req.SubjectKeyId)
}

if !s.ca.IsUpstreamAuthority() {
Expand All @@ -396,7 +396,6 @@ func (s *Service) TaintX509UpstreamAuthority(ctx context.Context, req *localauth

if err := s.ds.TaintX509CA(ctx, s.td.IDString(), subjectKeyIDRequest); err != nil {
return nil, api.MakeErr(log, codes.Internal, "failed to taint upstream authority", err)

}

rpccontext.AuditRPC(ctx)
Expand Down Expand Up @@ -443,7 +442,7 @@ func (s *Service) RevokeX509UpstreamAuthority(ctx context.Context, req *localaut
log := rpccontext.Logger(ctx)

if req.SubjectKeyId != "" {
log = log.WithField(telemetry.SubjectKeyId, req.SubjectKeyId)
log = log.WithField(telemetry.SubjectKeyID, req.SubjectKeyId)
}

if !s.ca.IsUpstreamAuthority() {
Expand Down Expand Up @@ -551,7 +550,7 @@ func buildAuditLogFields(authorityID string) logrus.Fields {
func buildAuditUpstreamLogFields(authorityID string) logrus.Fields {
fields := logrus.Fields{}
if authorityID != "" {
fields[telemetry.SubjectKeyId] = authorityID
fields[telemetry.SubjectKeyID] = authorityID
}
return fields
}
Expand Down
52 changes: 26 additions & 26 deletions pkg/server/api/localauthority/v1/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1627,14 +1627,14 @@ func TestTaintX509UpstreamAuthority(t *testing.T) {
Data: logrus.Fields{
telemetry.Status: "success",
telemetry.Type: "audit",
telemetry.SubjectKeyId: deactivatedUpstreamAuthorityID,
telemetry.SubjectKeyID: deactivatedUpstreamAuthorityID,
},
},
{
Level: logrus.InfoLevel,
Message: "X.509 upstream authority tainted successfully",
Data: logrus.Fields{
telemetry.SubjectKeyId: deactivatedUpstreamAuthorityID,
telemetry.SubjectKeyID: deactivatedUpstreamAuthorityID,
},
},
},
Expand All @@ -1652,7 +1652,7 @@ func TestTaintX509UpstreamAuthority(t *testing.T) {
Level: logrus.ErrorLevel,
Message: "Upstream authority is not configured",
Data: logrus.Fields{
telemetry.SubjectKeyId: deactivatedUpstreamAuthorityID,
telemetry.SubjectKeyID: deactivatedUpstreamAuthorityID,
},
},
{
Expand All @@ -1663,7 +1663,7 @@ func TestTaintX509UpstreamAuthority(t *testing.T) {
telemetry.StatusCode: "FailedPrecondition",
telemetry.StatusMessage: "upstream authority is not configured",
telemetry.Type: "audit",
telemetry.SubjectKeyId: deactivatedUpstreamAuthorityID,
telemetry.SubjectKeyID: deactivatedUpstreamAuthorityID,
},
},
},
Expand Down Expand Up @@ -1707,7 +1707,7 @@ func TestTaintX509UpstreamAuthority(t *testing.T) {
Message: "Invalid argument: provided subject key id is not valid",
Data: logrus.Fields{
logrus.ErrorKey: "unable to use upstream authority singing current authority",
telemetry.SubjectKeyId: activeUpstreamAuthorityID,
telemetry.SubjectKeyID: activeUpstreamAuthorityID,
},
},
{
Expand All @@ -1718,13 +1718,13 @@ func TestTaintX509UpstreamAuthority(t *testing.T) {
telemetry.StatusCode: "InvalidArgument",
telemetry.StatusMessage: "provided subject key id is not valid: unable to use upstream authority singing current authority",
telemetry.Type: "audit",
telemetry.SubjectKeyId: activeUpstreamAuthorityID,
telemetry.SubjectKeyID: activeUpstreamAuthorityID,
},
},
},
},
{
name: "unknwon subjectKeyID",
name: "unknown subjectKeyID",
currentSlot: createSlotWithUpstream(journal.Status_ACTIVE, currentIntermediateCA, notAfterCurrent),
nextSlot: createSlotWithUpstream(journal.Status_OLD, nextIntermediateCA, notAfterNext),
subjectKeyIDToTaint: "invalidID",
Expand All @@ -1736,7 +1736,7 @@ func TestTaintX509UpstreamAuthority(t *testing.T) {
Message: "Invalid argument: provided subject key id is not valid",
Data: logrus.Fields{
logrus.ErrorKey: "upstream authority is not signing Old local authority",
telemetry.SubjectKeyId: "invalidID",
telemetry.SubjectKeyID: "invalidID",
},
},
{
Expand All @@ -1747,7 +1747,7 @@ func TestTaintX509UpstreamAuthority(t *testing.T) {
telemetry.StatusCode: "InvalidArgument",
telemetry.StatusMessage: "provided subject key id is not valid: upstream authority is not signing Old local authority",
telemetry.Type: "audit",
telemetry.SubjectKeyId: "invalidID",
telemetry.SubjectKeyID: "invalidID",
},
},
},
Expand All @@ -1765,7 +1765,7 @@ func TestTaintX509UpstreamAuthority(t *testing.T) {
Message: "Invalid argument: provided subject key id is not valid",
Data: logrus.Fields{
logrus.ErrorKey: "only upstream authorities signing an old authority can be used",
telemetry.SubjectKeyId: deactivatedUpstreamAuthorityID,
telemetry.SubjectKeyID: deactivatedUpstreamAuthorityID,
},
},
{
Expand All @@ -1776,7 +1776,7 @@ func TestTaintX509UpstreamAuthority(t *testing.T) {
telemetry.StatusCode: "InvalidArgument",
telemetry.StatusMessage: "provided subject key id is not valid: only upstream authorities signing an old authority can be used",
telemetry.Type: "audit",
telemetry.SubjectKeyId: deactivatedUpstreamAuthorityID,
telemetry.SubjectKeyID: deactivatedUpstreamAuthorityID,
},
},
},
Expand All @@ -1799,7 +1799,7 @@ func TestTaintX509UpstreamAuthority(t *testing.T) {
Message: "Failed to taint upstream authority",
Data: logrus.Fields{
logrus.ErrorKey: "rpc error: code = NotFound desc = no ca found with provided subject key ID",
telemetry.SubjectKeyId: deactivatedUpstreamAuthorityID,
telemetry.SubjectKeyID: deactivatedUpstreamAuthorityID,
},
},
{
Expand All @@ -1810,7 +1810,7 @@ func TestTaintX509UpstreamAuthority(t *testing.T) {
telemetry.StatusCode: "Internal",
telemetry.StatusMessage: "failed to taint upstream authority: no ca found with provided subject key ID",
telemetry.Type: "audit",
telemetry.SubjectKeyId: deactivatedUpstreamAuthorityID,
telemetry.SubjectKeyID: deactivatedUpstreamAuthorityID,
},
},
},
Expand Down Expand Up @@ -2166,14 +2166,14 @@ func TestRevokeX509UpstreamAuthority(t *testing.T) {
Data: logrus.Fields{
telemetry.Status: "success",
telemetry.Type: "audit",
telemetry.SubjectKeyId: deactivatedUpstreamAuthorityID,
telemetry.SubjectKeyID: deactivatedUpstreamAuthorityID,
},
},
{
Level: logrus.InfoLevel,
Message: "X.509 upstream authority revoked successfully",
Data: logrus.Fields{
telemetry.SubjectKeyId: deactivatedUpstreamAuthorityID,
telemetry.SubjectKeyID: deactivatedUpstreamAuthorityID,
},
},
},
Expand All @@ -2191,7 +2191,7 @@ func TestRevokeX509UpstreamAuthority(t *testing.T) {
Level: logrus.ErrorLevel,
Message: "Upstream authority is not configured",
Data: logrus.Fields{
telemetry.SubjectKeyId: deactivatedUpstreamAuthorityID,
telemetry.SubjectKeyID: deactivatedUpstreamAuthorityID,
},
},
{
Expand All @@ -2202,7 +2202,7 @@ func TestRevokeX509UpstreamAuthority(t *testing.T) {
telemetry.StatusCode: "FailedPrecondition",
telemetry.StatusMessage: "upstream authority is not configured",
telemetry.Type: "audit",
telemetry.SubjectKeyId: deactivatedUpstreamAuthorityID,
telemetry.SubjectKeyID: deactivatedUpstreamAuthorityID,
},
},
},
Expand Down Expand Up @@ -2246,7 +2246,7 @@ func TestRevokeX509UpstreamAuthority(t *testing.T) {
Message: "Invalid argument: invalid subject key ID",
Data: logrus.Fields{
logrus.ErrorKey: "unable to use upstream authority singing current authority",
telemetry.SubjectKeyId: activeUpstreamAuthorityID,
telemetry.SubjectKeyID: activeUpstreamAuthorityID,
},
},
{
Expand All @@ -2257,13 +2257,13 @@ func TestRevokeX509UpstreamAuthority(t *testing.T) {
telemetry.StatusCode: "InvalidArgument",
telemetry.StatusMessage: "invalid subject key ID: unable to use upstream authority singing current authority",
telemetry.Type: "audit",
telemetry.SubjectKeyId: activeUpstreamAuthorityID,
telemetry.SubjectKeyID: activeUpstreamAuthorityID,
},
},
},
},
{
name: "unknwon subjectKeyID",
name: "unknown subjectKeyID",
currentSlot: createSlotWithUpstream(journal.Status_ACTIVE, currentIntermediateCA, notAfterCurrent),
nextSlot: createSlotWithUpstream(journal.Status_OLD, nextIntermediateCA, notAfterNext),
subjectKeyIDToRevoke: "invalidID",
Expand All @@ -2275,7 +2275,7 @@ func TestRevokeX509UpstreamAuthority(t *testing.T) {
Message: "Invalid argument: invalid subject key ID",
Data: logrus.Fields{
logrus.ErrorKey: "upstream authority is not signing Old local authority",
telemetry.SubjectKeyId: "invalidID",
telemetry.SubjectKeyID: "invalidID",
},
},
{
Expand All @@ -2286,7 +2286,7 @@ func TestRevokeX509UpstreamAuthority(t *testing.T) {
telemetry.StatusCode: "InvalidArgument",
telemetry.StatusMessage: "invalid subject key ID: upstream authority is not signing Old local authority",
telemetry.Type: "audit",
telemetry.SubjectKeyId: "invalidID",
telemetry.SubjectKeyID: "invalidID",
},
},
},
Expand All @@ -2304,7 +2304,7 @@ func TestRevokeX509UpstreamAuthority(t *testing.T) {
Message: "Invalid argument: invalid subject key ID",
Data: logrus.Fields{
logrus.ErrorKey: "only upstream authorities signing an old authority can be used",
telemetry.SubjectKeyId: deactivatedUpstreamAuthorityID,
telemetry.SubjectKeyID: deactivatedUpstreamAuthorityID,
},
},
{
Expand All @@ -2315,7 +2315,7 @@ func TestRevokeX509UpstreamAuthority(t *testing.T) {
telemetry.StatusCode: "InvalidArgument",
telemetry.StatusMessage: "invalid subject key ID: only upstream authorities signing an old authority can be used",
telemetry.Type: "audit",
telemetry.SubjectKeyId: deactivatedUpstreamAuthorityID,
telemetry.SubjectKeyID: deactivatedUpstreamAuthorityID,
},
},
},
Expand All @@ -2334,7 +2334,7 @@ func TestRevokeX509UpstreamAuthority(t *testing.T) {
Message: "Failed to revoke X.509 upstream authority",
Data: logrus.Fields{
logrus.ErrorKey: "rpc error: code = InvalidArgument desc = it is not possible to revoke an untainted root CA",
telemetry.SubjectKeyId: deactivatedUpstreamAuthorityID,
telemetry.SubjectKeyID: deactivatedUpstreamAuthorityID,
},
},
{
Expand All @@ -2345,7 +2345,7 @@ func TestRevokeX509UpstreamAuthority(t *testing.T) {
telemetry.StatusCode: "Internal",
telemetry.StatusMessage: "failed to revoke X.509 upstream authority: it is not possible to revoke an untainted root CA",
telemetry.Type: "audit",
telemetry.SubjectKeyId: deactivatedUpstreamAuthorityID,
telemetry.SubjectKeyID: deactivatedUpstreamAuthorityID,
},
},
},
Expand Down
14 changes: 7 additions & 7 deletions pkg/server/ca/manager/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ func (j *Journal) AppendX509CA(ctx context.Context, slotID string, issuedAt time

backup := j.entries.X509CAs
j.entries.X509CAs = append(j.entries.X509CAs, &journal.X509CAEntry{
SlotId: slotID,
IssuedAt: issuedAt.Unix(),
NotAfter: x509CA.Certificate.NotAfter.Unix(),
Certificate: x509CA.Certificate.Raw,
UpstreamChain: chainDER(x509CA.UpstreamChain),
Status: journal.Status_PREPARED,
AuthorityId: x509util.SubjectKeyIDToString(x509CA.Certificate.SubjectKeyId),
SlotId: slotID,
IssuedAt: issuedAt.Unix(),
NotAfter: x509CA.Certificate.NotAfter.Unix(),
Certificate: x509CA.Certificate.Raw,
UpstreamChain: chainDER(x509CA.UpstreamChain),
Status: journal.Status_PREPARED,
AuthorityId: x509util.SubjectKeyIDToString(x509CA.Certificate.SubjectKeyId),
UpstreamAuthorityId: x509util.SubjectKeyIDToString(x509CA.Certificate.AuthorityKeyId),
})

Expand Down
4 changes: 2 additions & 2 deletions pkg/server/ca/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ func (u *bundleUpdater) SyncX509Roots(ctx context.Context, roots []*x509certific
if err := u.ds.TaintX509CA(ctx, u.trustDomainID, skID); err != nil {
return fmt.Errorf("failed to taint x.509 authority %q: %w", skID, err)
}
u.log.WithField(telemetry.SubjectKeyId, skID).Info("X.509 authority tainted")
u.log.WithField(telemetry.SubjectKeyID, skID).Info("X.509 authority tainted")
// Prevent to add tainted keys, since status is updated before
continue
}
Expand All @@ -778,7 +778,7 @@ func (u *bundleUpdater) SyncX509Roots(ctx context.Context, roots []*x509certific
if err := u.ds.RevokeX509CA(ctx, u.trustDomainID, skID); err != nil {
return fmt.Errorf("failed to revoke a tainted key %q: %w", skID, err)
}
u.log.WithField(telemetry.SubjectKeyId, skID).Info("X.509 authority revoked")
u.log.WithField(telemetry.SubjectKeyID, skID).Info("X.509 authority revoked")
}
}
}
Expand Down

0 comments on commit fc7b2b4

Please sign in to comment.