Skip to content

Commit

Permalink
Refactor process state into its own package (#41630)
Browse files Browse the repository at this point in the history
Creates a new lib/auth/state package that now contains all items
related to process identity and local storage. Since these things
are consumed by client tools isolating them in their own package
will allow tools to trim the dependency tree by shedding lib/auth
for a smaller package. No functional changes have been added in
addition to moving code around. There are aliases to the old
types left around to prevent breaking builds. They will be removed
in a follow up when teleport.e is updated to consume the new package.
  • Loading branch information
rosstimothy authored May 16, 2024
1 parent 2cf0360 commit abd15f3
Show file tree
Hide file tree
Showing 25 changed files with 481 additions and 418 deletions.
6 changes: 3 additions & 3 deletions integration/helpers/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ import (
"github.com/gravitational/teleport/api/breaker"
clientproto "github.com/gravitational/teleport/api/client/proto"
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/lib/auth"
"github.com/gravitational/teleport/lib/auth/authclient"
"github.com/gravitational/teleport/lib/auth/keygen"
"github.com/gravitational/teleport/lib/auth/state"
"github.com/gravitational/teleport/lib/auth/testauthority"
"github.com/gravitational/teleport/lib/backend"
"github.com/gravitational/teleport/lib/backend/lite"
Expand Down Expand Up @@ -255,8 +255,8 @@ func (s *InstanceSecrets) AsSlice() []*InstanceSecrets {
return []*InstanceSecrets{s}
}

func (s *InstanceSecrets) GetIdentity() *auth.Identity {
i, err := auth.ReadIdentityFromKeyPair(s.PrivKey, &clientproto.Certs{
func (s *InstanceSecrets) GetIdentity() *state.Identity {
i, err := state.ReadIdentityFromKeyPair(s.PrivKey, &clientproto.Certs{
SSH: s.Cert,
TLS: s.TLSCert,
TLSCACerts: [][]byte{s.TLSCACert},
Expand Down
6 changes: 3 additions & 3 deletions integration/hsm/hsm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import (
"github.com/gravitational/teleport/api/breaker"
"github.com/gravitational/teleport/api/client"
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/lib/auth"
"github.com/gravitational/teleport/lib/auth/authclient"
"github.com/gravitational/teleport/lib/auth/keystore"
"github.com/gravitational/teleport/lib/auth/state"
"github.com/gravitational/teleport/lib/backend"
"github.com/gravitational/teleport/lib/backend/etcdbk"
"github.com/gravitational/teleport/lib/backend/lite"
Expand Down Expand Up @@ -181,9 +181,9 @@ func TestHSMRotation(t *testing.T) {
}

func getAdminClient(authDataDir string, authAddr string) (*authclient.Client, error) {
identity, err := auth.ReadLocalIdentity(
identity, err := state.ReadLocalIdentity(
filepath.Join(authDataDir, teleport.ComponentProcess),
auth.IdentityID{Role: types.RoleAdmin})
state.IdentityID{Role: types.RoleAdmin})
if err != nil {
return nil, trace.Wrap(err)
}
Expand Down
3 changes: 2 additions & 1 deletion integration/proxy/proxy_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import (
"github.com/gravitational/teleport/integration/helpers"
"github.com/gravitational/teleport/lib"
"github.com/gravitational/teleport/lib/auth"
"github.com/gravitational/teleport/lib/auth/state"
"github.com/gravitational/teleport/lib/client"
"github.com/gravitational/teleport/lib/defaults"
"github.com/gravitational/teleport/lib/fixtures"
Expand Down Expand Up @@ -665,7 +666,7 @@ func mustRegisterUsingIAMMethod(t *testing.T, proxyAddr utils.NetAddr, token str
node := uuid.NewString()
_, err = auth.Register(context.TODO(), auth.RegisterParams{
Token: token,
ID: auth.IdentityID{
ID: state.IdentityID{
Role: types.RoleNode,
HostUUID: node,
NodeName: node,
Expand Down
7 changes: 4 additions & 3 deletions lib/auth/bot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/lib/auth/authclient"
"github.com/gravitational/teleport/lib/auth/machineid/machineidv1"
"github.com/gravitational/teleport/lib/auth/state"
"github.com/gravitational/teleport/lib/auth/testauthority"
"github.com/gravitational/teleport/lib/cloud/azure"
"github.com/gravitational/teleport/lib/fixtures"
Expand Down Expand Up @@ -119,7 +120,7 @@ func TestRegisterBotCertificateGenerationCheck(t *testing.T) {

certs, err := Register(ctx, RegisterParams{
Token: token.GetName(),
ID: IdentityID{
ID: state.IdentityID{
Role: types.RoleBot,
},
AuthServers: []utils.NetAddr{*utils.MustParseAddr(srv.Addr().String())},
Expand Down Expand Up @@ -192,7 +193,7 @@ func TestRegisterBotCertificateGenerationStolen(t *testing.T) {

certs, err := Register(ctx, RegisterParams{
Token: token.GetName(),
ID: IdentityID{
ID: state.IdentityID{
Role: types.RoleBot,
},
AuthServers: []utils.NetAddr{*utils.MustParseAddr(srv.Addr().String())},
Expand Down Expand Up @@ -268,7 +269,7 @@ func TestRegisterBotCertificateExtensions(t *testing.T) {

certs, err := Register(ctx, RegisterParams{
Token: token.GetName(),
ID: IdentityID{
ID: state.IdentityID{
Role: types.RoleBot,
},
AuthServers: []utils.NetAddr{*utils.MustParseAddr(srv.Addr().String())},
Expand Down
7 changes: 4 additions & 3 deletions lib/auth/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
"github.com/gravitational/teleport/lib/auth/authclient"
"github.com/gravitational/teleport/lib/auth/keystore"
"github.com/gravitational/teleport/lib/auth/native"
"github.com/gravitational/teleport/lib/auth/state"
authority "github.com/gravitational/teleport/lib/auth/testauthority"
"github.com/gravitational/teleport/lib/authz"
"github.com/gravitational/teleport/lib/backend"
Expand Down Expand Up @@ -802,7 +803,7 @@ type TestTLSServer struct {
// TestTLSServerConfig is a configuration for TLS server
TestTLSServerConfig
// Identity is a generated TLS/SSH identity used to answer in TLS
Identity *Identity
Identity *state.Identity
// TLSServer is a configured TLS server
TLSServer *TLSServer
}
Expand Down Expand Up @@ -1141,7 +1142,7 @@ func (t *TestTLSServer) Stop() error {
}

// NewServerIdentity generates new server identity, used in tests
func NewServerIdentity(clt *Server, hostID string, role types.SystemRole) (*Identity, error) {
func NewServerIdentity(clt *Server, hostID string, role types.SystemRole) (*state.Identity, error) {
priv, pub, err := native.GenerateKeyPair()
if err != nil {
return nil, trace.Wrap(err)
Expand All @@ -1164,7 +1165,7 @@ func NewServerIdentity(clt *Server, hostID string, role types.SystemRole) (*Iden
return nil, trace.Wrap(err)
}

return ReadIdentityFromKeyPair(priv, certs)
return state.ReadIdentityFromKeyPair(priv, certs)
}

// clt limits required interface to the necessary methods
Expand Down
Loading

0 comments on commit abd15f3

Please sign in to comment.