Skip to content

Commit

Permalink
Add commands for autoupdate
Browse files Browse the repository at this point in the history
  • Loading branch information
vapopov committed Aug 21, 2024
1 parent 61c3443 commit bd8e1d3
Show file tree
Hide file tree
Showing 17 changed files with 786 additions and 376 deletions.
15 changes: 15 additions & 0 deletions api/client/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/gravitational/teleport/api/client/proto"
accessmonitoringrulesv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/accessmonitoringrules/v1"
"github.com/gravitational/teleport/api/gen/proto/go/teleport/autoupdate/v1"
clusterconfigpb "github.com/gravitational/teleport/api/gen/proto/go/teleport/clusterconfig/v1"
crownjewelv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/crownjewel/v1"
dbobjectv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/dbobject/v1"
Expand Down Expand Up @@ -99,6 +100,14 @@ func EventToGRPC(in types.Event) (*proto.Event, error) {
out.Resource = &proto.Event_StaticHostUser{
StaticHostUser: r,
}
case *autoupdate.ClusterAutoUpdateConfig:
out.Resource = &proto.Event_ClusterAutoUpdateConfig{
ClusterAutoUpdateConfig: r,
}
case *autoupdate.AutoUpdateVersion:
out.Resource = &proto.Event_AutoUpdateVersion{
AutoUpdateVersion: r,
}
default:
return nil, trace.BadParameter("resource type %T is not supported", r)
}
Expand Down Expand Up @@ -542,6 +551,12 @@ func EventFromGRPC(in *proto.Event) (*types.Event, error) {
} else if r := in.GetStaticHostUser(); r != nil {
out.Resource = types.Resource153ToLegacy(r)
return &out, nil
} else if r := in.GetClusterAutoUpdateConfig(); r != nil {
out.Resource = types.Resource153ToLegacy(r)
return &out, nil
} else if r := in.GetAutoUpdateVersion(); r != nil {
out.Resource = types.Resource153ToLegacy(r)
return &out, nil
} else {
return nil, trace.BadParameter("received unsupported resource %T", in.Resource)
}
Expand Down
672 changes: 362 additions & 310 deletions api/client/proto/event.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/client/webclient/webclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ type PingResponse struct {
// ToolsVersion defines the version of {tsh, tctl} for client auto-upgrade.
ToolsVersion string `json:"tools_version"`
// ToolsAutoUpdate enables client autoupdate feature.
ToolsAutoUpdate bool `json:"tools_auto_update"`
ToolsAutoUpdate string `json:"tools_auto_update"`
// ClusterName contains the name of the Teleport cluster.
ClusterName string `json:"cluster_name"`

Expand Down
40 changes: 20 additions & 20 deletions api/gen/proto/go/teleport/autoupdate/v1/autoupdate.pb.go

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

6 changes: 3 additions & 3 deletions api/proto/teleport/autoupdate/v1/autoupdate.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ message ClusterAutoUpdateConfig {
// ClusterAutoupdateConfigSpecV1 encodes the parameters of the autoupdate config object.
message ClusterAutoUpdateConfigSpec {
// ToolsAutoUpdate encodes the feature flag to enable/disable tools autoupdates.
bool tools_auto_update = 1;
string tools_auto_update = 1;
}

// AutoupdateVersionV1 is a resource singleton with version required for
Expand All @@ -45,11 +45,11 @@ message AutoUpdateVersion {
string version = 3;
teleport.header.v1.Metadata metadata = 4;

AutoupdateVersionSpec spec = 5;
AutoUpdateVersionSpec spec = 5;
}

// AutoupdateVersionSpecV1 encodes the parameters of the autoupdate versions.
message AutoupdateVersionSpec {
message AutoUpdateVersionSpec {
// ToolsVersion is the semantic version required for tools autoupdates.
string tools_version = 1;
}
5 changes: 5 additions & 0 deletions api/proto/teleport/legacy/client/proto/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package proto;

import "teleport/accesslist/v1/accesslist.proto";
import "teleport/accessmonitoringrules/v1/access_monitoring_rules.proto";
import "teleport/autoupdate/v1/autoupdate.proto";
import "teleport/clusterconfig/v1/access_graph_settings.proto";
import "teleport/crownjewel/v1/crownjewel.proto";
import "teleport/dbobject/v1/dbobject.proto";
Expand Down Expand Up @@ -177,5 +178,9 @@ message Event {
teleport.machineid.v1.SPIFFEFederation SPIFFEFederation = 62;
// StaticHostUser is a resource for static host users.
teleport.userprovisioning.v1.StaticHostUser StaticHostUser = 63;
// ClusterAutoUpdateConfig is a resource for cluster autoupdate config.
teleport.autoupdate.v1.ClusterAutoUpdateConfig ClusterAutoUpdateConfig = 64;
// AutoUpdateVersion is a resource for autoupdate version.
teleport.autoupdate.v1.AutoUpdateVersion AutoUpdateVersion = 65;
}
}
60 changes: 60 additions & 0 deletions api/types/autoupdate/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Teleport
* Copyright (C) 2024 Gravitational, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package autoupdate

import (
"github.com/gravitational/trace"

"github.com/gravitational/teleport/api/gen/proto/go/teleport/autoupdate/v1"
headerv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/header/v1"
"github.com/gravitational/teleport/api/types"
)

// NewClusterAutoUpdateConfig creates a new cluster autoupdate configuration resource.
func NewClusterAutoUpdateConfig(spec *autoupdate.ClusterAutoUpdateConfigSpec) (*autoupdate.ClusterAutoUpdateConfig, error) {
config := &autoupdate.ClusterAutoUpdateConfig{
Kind: types.KindClusterAutoUpdateConfig,
Version: types.V1,
Metadata: &headerv1.Metadata{
Name: types.MetaNameClusterAutoUpdateConfig,
},
Spec: spec,
}
if err := ValidateClusterAutoUpdateConfig(config); err != nil {
return nil, trace.Wrap(err)
}

return config, nil
}

// ValidateClusterAutoUpdateConfig checks that required parameters are set
// for the specified ClusterAutoUpdateConfig.
func ValidateClusterAutoUpdateConfig(c *autoupdate.ClusterAutoUpdateConfig) error {
if c == nil {
return trace.BadParameter("ClusterAutoUpdateConfig is nil")
}
if c.Metadata == nil {
return trace.BadParameter("Metadata is nil")
}
if c.Spec == nil {
return trace.BadParameter("Spec is nil")
}

return nil
}
64 changes: 64 additions & 0 deletions api/types/autoupdate/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Teleport
* Copyright (C) 2024 Gravitational, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package autoupdate

import (
"github.com/gravitational/trace"

"github.com/gravitational/teleport/api/gen/proto/go/teleport/autoupdate/v1"
headerv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/header/v1"
"github.com/gravitational/teleport/api/types"
)

// NewAutoUpdateVersion creates a new autoupdate version resource.
func NewAutoUpdateVersion(spec *autoupdate.AutoUpdateVersionSpec) (*autoupdate.AutoUpdateVersion, error) {
version := &autoupdate.AutoUpdateVersion{
Kind: types.KindAutoUpdateVersion,
Version: types.V1,
Metadata: &headerv1.Metadata{
Name: types.MetaNameAutoUpdateVersion,
},
Spec: spec,
}
if err := ValidateAutoUpdateVersion(version); err != nil {
return nil, trace.Wrap(err)
}

return version, nil
}

// ValidateAutoUpdateVersion checks that required parameters are set
// for the specified AutoUpdateVersion.
func ValidateAutoUpdateVersion(v *autoupdate.AutoUpdateVersion) error {
if v == nil {
return trace.BadParameter("AutoUpdateVersion is nil")
}
if v.Metadata == nil {
return trace.BadParameter("Metadata is nil")
}
if v.Spec == nil {
return trace.BadParameter("Spec is nil")
}

if v.Spec.ToolsVersion == "" {
return trace.BadParameter("ToolsVersion is unset")
}

return nil
}
4 changes: 2 additions & 2 deletions lib/auth/accesspoint/accesspoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ type Config struct {
WebSession types.WebSessionInterface
WebToken types.WebTokenInterface
WindowsDesktops services.WindowsDesktops
ClusterAutoUpdate services.AutoUpdateService
AutoUpdateService services.AutoUpdateService
}

func (c *Config) CheckAndSetDefaults() error {
Expand Down Expand Up @@ -168,7 +168,7 @@ func NewCache(cfg Config) (*cache.Cache, error) {
AppSession: cfg.AppSession,
Apps: cfg.Apps,
ClusterConfig: cfg.ClusterConfig,
AutoUpdateService: cfg.ClusterAutoUpdate,
AutoUpdateService: cfg.AutoUpdateService,
CrownJewels: cfg.CrownJewels,
DatabaseObjects: cfg.DatabaseObjects,
DatabaseServices: cfg.DatabaseServices,
Expand Down
1 change: 1 addition & 0 deletions lib/auth/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ func NewTestAuthServer(cfg TestAuthServerConfig) (*TestAuthServer, error) {
AppSession: svces.Identity,
Apps: svces.Apps,
ClusterConfig: svces.ClusterConfiguration,
AutoUpdateService: svces.AutoUpdateService,
CrownJewels: svces.CrownJewels,
DatabaseObjects: svces.DatabaseObjects,
DatabaseServices: svces.DatabaseServices,
Expand Down
Loading

0 comments on commit bd8e1d3

Please sign in to comment.