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

[v1.14] Add SPIRE connection to status #27649

Merged
merged 1 commit into from
Sep 5, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 46 additions & 0 deletions api/v1/models/status_response.go
joestringer marked this conversation as resolved.
Show resolved Hide resolved

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 @@ -1959,6 +1959,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 @@ -217,6 +218,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
}

func (d *Daemon) initDNSProxyContext(size int) {
Expand Down Expand Up @@ -545,6 +549,7 @@ func newDaemon(ctx context.Context, cleaner *daemonCleanup, params *daemonParams
l2announcer: params.L2Announcer,
l7Proxy: params.L7Proxy,
db: params.DB,
authManager: params.AuthManager,
}

d.configModifyQueue = eventqueue.NewEventQueueBuffered("config-modify-queue", ConfigModifyQueueSize)
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 @@ -27,6 +27,7 @@ import (
"github.com/cilium/cilium/daemon/cmd/cni"
agentK8s "github.com/cilium/cilium/daemon/k8s"
"github.com/cilium/cilium/pkg/api"
"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 @@ -1620,6 +1621,7 @@ type daemonParams struct {
L2Announcer *l2announcer.L2Announcer
L7Proxy *proxy.Proxy
DB statedb.DB
AuthManager *auth.AuthManager
}

func newDaemonPromise(params daemonParams) promise.Promise[*Daemon] {
Expand Down
20 changes: 20 additions & 0 deletions daemon/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,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 @@ -86,10 +86,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 @@ -99,7 +99,7 @@ func registerAuthManager(params authManagerParams) error {

mgr, err := newAuthManager(params.Logger, params.AuthHandlers, mapCache, params.IPCache, params.Config.MeshAuthSignalBackoffDuration)
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.IPCache, params.PolicyRepo)
Expand All @@ -122,25 +122,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
}