Skip to content

Commit

Permalink
Add SPIRE connection to status
Browse files Browse the repository at this point in the history
This adds the SPIRE connection to cilium status, this then can be used
by the CLI tool to surface errors and/or wait for SPIRE to be ready.
If Auth is disabled it will surface the disabled status.

Signed-off-by: Maartje Eyskens <maartje.eyskens@isovalent.com>
  • Loading branch information
meyskens authored and ldelossa committed Aug 11, 2023
1 parent 916a2ce commit 1410a66
Show file tree
Hide file tree
Showing 17 changed files with 198 additions and 22 deletions.
46 changes: 46 additions & 0 deletions api/v1/models/status_response.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions api/v1/models/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions api/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2133,6 +2133,9 @@ definitions:
cni-chaining:
description: Status of CNI chaining
"$ref": "#/definitions/CNIChainingStatus"
auth-certificate-provider:
description: Status of Mutual Authentication certificate provider
"$ref": "#/definitions/Status"
Status:
description: Status of an individual component
type: object
Expand Down
8 changes: 8 additions & 0 deletions api/v1/server/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions daemon/cmd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/cilium/cilium/api/v1/models"
health "github.com/cilium/cilium/cilium-health/launch"
"github.com/cilium/cilium/daemon/cmd/cni"
"github.com/cilium/cilium/pkg/auth"
"github.com/cilium/cilium/pkg/bandwidth"
"github.com/cilium/cilium/pkg/bgp/speaker"
bgpv1 "github.com/cilium/cilium/pkg/bgpv1/agent"
Expand Down Expand Up @@ -218,6 +219,9 @@ type Daemon struct {
// statedb for implementing /statedb/dump
db statedb.DB

// authManager for reporting the status of the auth system certificate provider
authManager *auth.AuthManager

// read-only map of all the hive settings
settings cellSettings
// enable modules health support
Expand Down Expand Up @@ -534,6 +538,7 @@ func newDaemon(ctx context.Context, cleaner *daemonCleanup, params *daemonParams
l2announcer: params.L2Announcer,
l7Proxy: params.L7Proxy,
db: params.DB,
authManager: params.AuthManager,
settings: params.Settings,
healthProvider: params.HealthProvider,
healthReporter: params.HealthReporter,
Expand Down
2 changes: 2 additions & 0 deletions daemon/cmd/daemon_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/cilium/cilium/api/v1/server"
"github.com/cilium/cilium/daemon/cmd/cni"
agentK8s "github.com/cilium/cilium/daemon/k8s"
"github.com/cilium/cilium/pkg/auth"
"github.com/cilium/cilium/pkg/aws/eni"
bgpv1 "github.com/cilium/cilium/pkg/bgpv1/agent"
"github.com/cilium/cilium/pkg/bpf"
Expand Down Expand Up @@ -1634,6 +1635,7 @@ type daemonParams struct {
L7Proxy *proxy.Proxy
DB statedb.DB
APILimiterSet *rate.APILimiterSet
AuthManager *auth.AuthManager
Settings cellSettings
HealthProvider cell.Health
HealthReporter cell.HealthReporter
Expand Down
20 changes: 20 additions & 0 deletions daemon/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,26 @@ func (d *Daemon) startStatusCollector(cleaner *daemonCleanup) {
}
},
},
{
Name: "auth-cert-provider",
Probe: func(ctx context.Context) (interface{}, error) {
if d.authManager == nil {
return &models.Status{State: models.StatusStateDisabled}, nil
}

return d.authManager.CertProviderStatus(), nil
},
OnStatusUpdate: func(status status.Status) {
d.statusCollectMutex.Lock()
defer d.statusCollectMutex.Unlock()

if status.Err == nil {
if s, ok := status.Data.(*models.Status); ok {
d.statusResponse.AuthCertificateProvider = s
}
}
},
},
}

d.statusResponse.Masquerading = d.getMasqueradingStatus()
Expand Down
5 changes: 5 additions & 0 deletions pkg/auth/always_fail_authhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package auth
import (
"errors"

"github.com/cilium/cilium/api/v1/models"
"github.com/cilium/cilium/pkg/auth/certs"
"github.com/cilium/cilium/pkg/policy"
)
Expand All @@ -31,3 +32,7 @@ func (r *alwaysFailAuthHandler) authType() policy.AuthType {
func (r *alwaysFailAuthHandler) subscribeToRotatedIdentities() <-chan certs.CertificateRotationEvent {
return nil
}

func (r *alwaysFailAuthHandler) certProviderStatus() *models.Status {
return nil // reporting no status as we have no cert provider
}
5 changes: 5 additions & 0 deletions pkg/auth/always_pass_authhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/sirupsen/logrus"

"github.com/cilium/cilium/api/v1/models"
"github.com/cilium/cilium/pkg/auth/certs"
"github.com/cilium/cilium/pkg/policy"
)
Expand Down Expand Up @@ -41,3 +42,7 @@ func (r *alwaysPassAuthHandler) authType() policy.AuthType {
func (r *alwaysPassAuthHandler) subscribeToRotatedIdentities() <-chan certs.CertificateRotationEvent {
return nil
}

func (r *alwaysPassAuthHandler) certProviderStatus() *models.Status {
return nil // reporting no status as we have no cert provider
}
18 changes: 9 additions & 9 deletions pkg/auth/cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/cilium/cilium/pkg/stream"
)

// Cell invokes authManager which is responsible for request authentication.
// Cell provides AuthManager which is responsible for request authentication.
// It does this by registering to "auth required" signals from the signal package
// and reacting upon received signal events.
// Actual authentication gets performed by an auth handler which is
Expand All @@ -37,7 +37,7 @@ var Cell = cell.Module(

// The auth manager is the main entry point which gets registered to signal map and receives auth requests.
// In addition, it handles re-authentication and auth map garbage collection.
cell.Invoke(registerAuthManager),
cell.Provide(registerAuthManager),
cell.ProvidePrivate(
// Null auth handler provides support for auth type "null" - which always succeeds.
newMutualAuthHandler,
Expand Down Expand Up @@ -82,10 +82,10 @@ type authManagerParams struct {
PolicyRepo *policy.Repository
}

func registerAuthManager(params authManagerParams) error {
func registerAuthManager(params authManagerParams) (*AuthManager, error) {
if !params.Config.MeshAuthEnabled {
params.Logger.Info("Authentication processing is disabled")
return nil
return nil, nil
}

// Instantiate & wire auth components
Expand All @@ -95,7 +95,7 @@ func registerAuthManager(params authManagerParams) error {

mgr, err := newAuthManager(params.Logger, params.AuthHandlers, mapCache, params.NodeIDHandler)
if err != nil {
return fmt.Errorf("failed to create auth manager: %w", err)
return nil, fmt.Errorf("failed to create auth manager: %w", err)
}

mapGC := newAuthMapGC(params.Logger, mapCache, params.NodeIDHandler, params.PolicyRepo)
Expand All @@ -118,25 +118,25 @@ func registerAuthManager(params authManagerParams) error {
)

if err := registerSignalAuthenticationJob(jobGroup, mgr, params.SignalManager, params.Config); err != nil {
return fmt.Errorf("failed to register signal authentication job: %w", err)
return nil, fmt.Errorf("failed to register signal authentication job: %w", err)
}
registerReAuthenticationJob(jobGroup, mgr, params.AuthHandlers)
registerGCJobs(jobGroup, params.Lifecycle, mapGC, params.Config, params.NodeManager, params.IdentityChanges)

params.Lifecycle.Append(jobGroup)

return nil
return mgr, nil
}

func registerReAuthenticationJob(jobGroup job.Group, mgr *authManager, authHandlers []authHandler) {
func registerReAuthenticationJob(jobGroup job.Group, mgr *AuthManager, authHandlers []authHandler) {
for _, ah := range authHandlers {
if ah != nil && ah.subscribeToRotatedIdentities() != nil {
jobGroup.Add(job.Observer("auth re-authentication", mgr.handleCertificateRotationEvent, stream.FromChannel(ah.subscribeToRotatedIdentities())))
}
}
}

func registerSignalAuthenticationJob(jobGroup job.Group, mgr *authManager, sm signal.SignalManager, config config) error {
func registerSignalAuthenticationJob(jobGroup job.Group, mgr *AuthManager, sm signal.SignalManager, config config) error {
var signalChannel = make(chan signalAuthKey, config.MeshAuthQueueSize)

// RegisterHandler registers signalChannel with SignalManager, but flow of events
Expand Down
4 changes: 4 additions & 0 deletions pkg/auth/certs/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"crypto/tls"
"crypto/x509"

"github.com/cilium/cilium/api/v1/models"
"github.com/cilium/cilium/pkg/identity"
)

Expand Down Expand Up @@ -36,4 +37,7 @@ type CertificateProvider interface {

// SubscribeToRotatedIdentities will return a channel with the identities that have rotated certificates
SubscribeToRotatedIdentities() <-chan CertificateRotationEvent

// Status will return the status of the certificate provider
Status() *models.Status
}

0 comments on commit 1410a66

Please sign in to comment.