-
Notifications
You must be signed in to change notification settings - Fork 22
Yyamout/public bootz server updates #314
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
base: main
Are you sure you want to change the base?
Changes from all commits
4cf9934
a7aab58
62b154d
1ca8730
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ import ( | |
| bpb "github.com/openconfig/bootz/proto/bootz" | ||
| epb "github.com/openconfig/bootz/server/entitymanager/proto/entity" | ||
| apb "github.com/openconfig/gnsi/authz" | ||
| ppb "github.com/openconfig/gnsi/pathz" | ||
| ) | ||
|
|
||
| const defaultRealm = "prod" | ||
|
|
@@ -74,6 +75,14 @@ func (m *InMemoryEntityManager) ResolveChassis(ctx context.Context, lookup *serv | |
| if err != nil { | ||
| return nil, err | ||
| } | ||
| credzConf, err := m.populateCredentialsConfig(chassis) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| pathzConf, err := m.populatePathzConfig(chassis) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| authzConf, err := m.populateAuthzConfig(chassis) | ||
| if err != nil { | ||
| return nil, err | ||
|
|
@@ -88,7 +97,10 @@ func (m *InMemoryEntityManager) ResolveChassis(ctx context.Context, lookup *serv | |
| Serial: chassis.GetSerialNumber(), | ||
| ControlCards: cards, | ||
| BootConfig: bootCfg, | ||
| Credentials: credzConf, | ||
| Pathz: pathzConf, | ||
| Authz: authzConf, | ||
| CertzProfiles: chassis.GetConfig().GetGnsiConfig().GetCertzProfiles(), | ||
| BootloaderPasswordHash: chassis.GetBootloaderPasswordHash(), | ||
| }, nil | ||
| } | ||
|
|
@@ -160,6 +172,48 @@ func (m *InMemoryEntityManager) populateAuthzConfig(ch *epb.Chassis) (*apb.Uploa | |
| return gnsiAuthzReq, nil | ||
| } | ||
|
|
||
| func (m *InMemoryEntityManager) populatePathzConfig(ch *epb.Chassis) (*ppb.UploadRequest, error) { | ||
| gnsiConf := ch.GetConfig().GetGnsiConfig() | ||
| gnsiPathzReq := gnsiConf.GetPathzUpload() | ||
| gnsiPathzReqFile := gnsiConf.GetPathzUploadFile() | ||
| if gnsiPathzReq.GetVersion() != "" && gnsiPathzReq.GetPolicy() != nil { | ||
| return gnsiPathzReq, nil | ||
| } | ||
| if gnsiPathzReqFile == "" { | ||
|
Comment on lines
+178
to
+182
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The populatePathzConfig function is missing a fallback to the global Pathz configuration if the chassis-specific configuration file is not provided. This is inconsistent with how populateAuthzConfig is implemented and will prevent global Pathz policies from being applied. gnsiPathzReqFile := gnsiConf.GetPathzUploadFile()
if gnsiPathzReqFile == "" && m.defaults != nil && m.defaults.GnsiGlobalConfig != nil {
gnsiPathzReqFile = m.defaults.GnsiGlobalConfig.GetPathzUploadFile()
}
if gnsiPathzReq.GetVersion() != "" && gnsiPathzReq.GetPolicy() != nil {
return gnsiPathzReq, nil
}
if gnsiPathzReqFile == "" { |
||
| return nil, nil | ||
| } | ||
| data, err := os.ReadFile(gnsiPathzReqFile) | ||
| if err != nil { | ||
| return nil, status.Errorf(codes.Internal, "Error opening file %s: %v", gnsiPathzReqFile, err) | ||
| } | ||
| gnsiPathzReq = &ppb.UploadRequest{} | ||
| if err := prototext.Unmarshal(data, gnsiPathzReq); err != nil { | ||
| return nil, status.Errorf(codes.Internal, "File %s config is not a valid pathz Upload Request: %v", gnsiPathzReqFile, err) | ||
| } | ||
| return gnsiPathzReq, nil | ||
| } | ||
|
|
||
| func (m *InMemoryEntityManager) populateCredentialsConfig(ch *epb.Chassis) (*bpb.Credentials, error) { | ||
| gnsiConf := ch.GetConfig().GetGnsiConfig() | ||
| gnsiCredzReq := gnsiConf.GetCredentials() | ||
| gnsiCredzReqFile := gnsiConf.GetCredentialsFile() | ||
| if len(gnsiCredzReq.GetCredentials()) > 0 || len(gnsiCredzReq.GetUsers()) > 0 || len(gnsiCredzReq.GetPasswords()) > 0 { | ||
| return gnsiCredzReq, nil | ||
| } | ||
| if gnsiCredzReqFile == "" { | ||
|
Comment on lines
+199
to
+203
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to populatePathzConfig, populateCredentialsConfig should also fallback to the global credentials configuration if the chassis-specific file is missing. gnsiCredzReqFile := gnsiConf.GetCredentialsFile()
if gnsiCredzReqFile == "" && m.defaults != nil && m.defaults.GnsiGlobalConfig != nil {
gnsiCredzReqFile = m.defaults.GnsiGlobalConfig.GetCredentialsFile()
}
if len(gnsiCredzReq.GetCredentials()) > 0 || len(gnsiCredzReq.GetUsers()) > 0 || len(gnsiCredzReq.GetPasswords()) > 0 {
return gnsiCredzReq, nil
}
if gnsiCredzReqFile == "" { |
||
| return nil, nil | ||
| } | ||
| data, err := os.ReadFile(gnsiCredzReqFile) | ||
| if err != nil { | ||
| return nil, status.Errorf(codes.Internal, "Error opening file %s: %v", gnsiCredzReqFile, err) | ||
| } | ||
| gnsiCredzReq = &bpb.Credentials{} | ||
| if err := prototext.Unmarshal(data, gnsiCredzReq); err != nil { | ||
| return nil, status.Errorf(codes.Internal, "File %s config is not valid Bootz credentials: %v", gnsiCredzReqFile, err) | ||
| } | ||
| return gnsiCredzReq, nil | ||
| } | ||
|
|
||
| func populateBootConfig(conf *epb.BootConfig) (*bpb.BootConfig, error) { | ||
| bootConfig := &bpb.BootConfig{} | ||
| if conf.GetOcConfigFile() != "" { | ||
|
|
@@ -186,16 +240,16 @@ func populateBootConfig(conf *epb.BootConfig) (*bpb.BootConfig, error) { | |
|
|
||
| // GetBootstrapData fetches and returns the bootstrap data response from the server. | ||
| func (m *InMemoryEntityManager) GetBootstrapData(ctx context.Context, chassis *service.Chassis, serial string) (*bpb.BootstrapDataResponse, error) { | ||
| // TODO: Populate gnsi config | ||
| return &bpb.BootstrapDataResponse{ | ||
| SerialNum: serial, | ||
| IntendedImage: chassis.SoftwareImage, | ||
| BootPasswordHash: chassis.BootloaderPasswordHash, | ||
| ServerTrustCert: base64.StdEncoding.EncodeToString(m.secArtifacts.TrustAnchor.Raw), | ||
| BootConfig: chassis.BootConfig, | ||
| Credentials: &bpb.Credentials{}, | ||
| // TODO: Populate pathz, authz and certificates. | ||
| Authz: chassis.Authz, | ||
| Credentials: chassis.Credentials, | ||
| Pathz: chassis.Pathz, | ||
| Authz: chassis.Authz, | ||
| CertzProfiles: chassis.CertzProfiles, | ||
| }, nil | ||
| } | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -32,7 +32,9 @@ import ( | |||||
| "github.com/openconfig/bootz/server/entitymanager" | ||||||
| "github.com/openconfig/bootz/server/service" | ||||||
| "google.golang.org/grpc" | ||||||
| "google.golang.org/grpc/codes" | ||||||
| "google.golang.org/grpc/credentials" | ||||||
| "google.golang.org/grpc/status" | ||||||
|
|
||||||
| bpb "github.com/openconfig/bootz/proto/bootz" | ||||||
| ) | ||||||
|
|
@@ -88,9 +90,37 @@ type InterceptorOpts struct { | |||||
|
|
||||||
| func (*InterceptorOpts) isbootzServerOpts() {} | ||||||
|
|
||||||
| // DisableBootstrapStream disables the deprecated BootstrapStream RPC while | ||||||
| // keeping unary RPCs available. | ||||||
| type DisableBootstrapStream struct{} | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to disable Streaming Bootz on the global sever level. bootz/server/service/service.go Line 693 in 02faee8
bootz/server/service/service.go Line 919 in 02faee8
|
||||||
|
|
||||||
| func (*DisableBootstrapStream) isbootzServerOpts() {} | ||||||
|
|
||||||
| type bootstrapServer struct { | ||||||
| bpb.UnimplementedBootstrapServer | ||||||
| service *service.Service | ||||||
| disableBootstrapStream bool | ||||||
| } | ||||||
|
|
||||||
| func (s *bootstrapServer) GetBootstrapData(ctx context.Context, req *bpb.GetBootstrapDataRequest) (*bpb.GetBootstrapDataResponse, error) { | ||||||
| return s.service.GetBootstrapData(ctx, req) | ||||||
| } | ||||||
|
|
||||||
| func (s *bootstrapServer) ReportStatus(ctx context.Context, req *bpb.ReportStatusRequest) (*bpb.EmptyResponse, error) { | ||||||
| return s.service.ReportStatus(ctx, req) | ||||||
| } | ||||||
|
|
||||||
| func (s *bootstrapServer) BootstrapStream(stream bpb.Bootstrap_BootstrapStreamServer) error { | ||||||
| if s.disableBootstrapStream { | ||||||
| return status.Error(codes.Unimplemented, "BootstrapStream disabled") | ||||||
| } | ||||||
| return s.service.BootstrapStream(stream) | ||||||
| } | ||||||
|
|
||||||
| // NewServer start a new Bootz gRPC , dhcp, and image server based on specified flags. | ||||||
| func NewServer(bootzAddr string, em *entitymanager.InMemoryEntityManager, sa *service.SecurityArtifacts, opts ...bootzServerOpts) (*Server, error) { | ||||||
| var interceptor grpc.ServerOption | ||||||
| disableBootstrapStream := false | ||||||
| server := &Server{} | ||||||
| for _, opt := range opts { | ||||||
| switch opt := opt.(type) { | ||||||
|
|
@@ -102,6 +132,8 @@ func NewServer(bootzAddr string, em *entitymanager.InMemoryEntityManager, sa *se | |||||
| server.httpSrv = StartImageServer(opt) | ||||||
| case *InterceptorOpts: | ||||||
| interceptor = grpc.UnaryInterceptor(opt.BootzInterceptor) | ||||||
| case *DisableBootstrapStream: | ||||||
| disableBootstrapStream = true | ||||||
| default: | ||||||
| continue | ||||||
| } | ||||||
|
|
@@ -124,7 +156,10 @@ func NewServer(bootzAddr string, em *entitymanager.InMemoryEntityManager, sa *se | |||||
| s = grpc.NewServer(grpc.Creds(credentials.NewTLS(tls))) | ||||||
| } | ||||||
|
|
||||||
| bpb.RegisterBootstrapServer(s, c) | ||||||
| bpb.RegisterBootstrapServer(s, &bootstrapServer{ | ||||||
| service: c, | ||||||
| disableBootstrapStream: disableBootstrapStream, | ||||||
| }) | ||||||
|
|
||||||
| lis, err := net.Listen("tcp", bootzAddr) | ||||||
| if err != nil { | ||||||
|
|
||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you sync your branch to the latest of main branch? |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are going to rewrite the entire EntityManager soon to utlize the "ChassisManager" interface.
bootz/server/service/service.go
Line 82 in 02faee8
It probably doesn't affect your PR, only as a heads-up.