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

Add cluster autoupdate resources with enabled cache #45617

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2844,6 +2844,24 @@ func (c *Client) GetClusterAuditConfig(ctx context.Context) (types.ClusterAuditC
return resp, nil
}

// GetClusterAutoUpdateConfig gets cluster autoupdate configuration.
func (c *Client) GetClusterAutoUpdateConfig(ctx context.Context) (types.ClusterAutoUpdateConfig, error) {
resp, err := c.grpc.GetClusterAutoUpdateConfig(ctx, &emptypb.Empty{})
if err != nil {
return nil, trace.Wrap(err)
}
return resp, nil
}

// GetAutoUpdateVersion gets cluster autoupdate version.
func (c *Client) GetAutoUpdateVersion(ctx context.Context) (types.AutoUpdateVersion, error) {
resp, err := c.grpc.GetAutoUpdateVersion(ctx, &emptypb.Empty{})
if err != nil {
return nil, trace.Wrap(err)
}
return resp, nil
}

// GetClusterAccessGraphConfig retrieves the Cluster Access Graph configuration from Auth server.
func (c *Client) GetClusterAccessGraphConfig(ctx context.Context) (*clusterconfigpb.AccessGraphConfig, error) {
rsp, err := c.ClusterConfigClient().GetClusterAccessGraphConfig(ctx, &clusterconfigpb.GetClusterAccessGraphConfigRequest{})
Expand Down
1,926 changes: 1,002 additions & 924 deletions api/client/proto/authservice.pb.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions api/client/webclient/webclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ type PingResponse struct {
ServerVersion string `json:"server_version"`
// MinClientVersion is the minimum client version required by the server.
MinClientVersion string `json:"min_client_version"`
// 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"`
// ClusterName contains the name of the Teleport cluster.
ClusterName string `json:"cluster_name"`

Expand Down
6 changes: 6 additions & 0 deletions api/proto/teleport/legacy/client/proto/authservice.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3514,6 +3514,12 @@ service AuthService {
// GetClusterMaintenanceConfig gets the current maintenance window config singleton.
rpc GetClusterMaintenanceConfig(google.protobuf.Empty) returns (types.ClusterMaintenanceConfigV1);

// GetClusterAutoUpdateConfig gets the current autoupdate config singleton.
rpc GetClusterAutoUpdateConfig(google.protobuf.Empty) returns (types.ClusterAutoUpdateConfigV1);

// GetAutoUpdateVersion gets the current autoupdate version singleton.
rpc GetAutoUpdateVersion(google.protobuf.Empty) returns (types.AutoUpdateVersionV1);

vapopov marked this conversation as resolved.
Show resolved Hide resolved
// UpdateClusterMaintenanceConfig updates the current maintenance window config singleton.
rpc UpdateClusterMaintenanceConfig(types.ClusterMaintenanceConfigV1) returns (google.protobuf.Empty);

Expand Down
46 changes: 46 additions & 0 deletions api/proto/teleport/legacy/types/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6624,6 +6624,52 @@ message AgentUpgradeWindow {
repeated string Weekdays = 2 [(gogoproto.jsontag) = "weekdays,omitempty"];
}

// ClusterAutoupdateConfigV1 is a config singleton used to configure cluster
// autoupdate settings.
message ClusterAutoUpdateConfigV1 {
ResourceHeader Header = 1 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "",
(gogoproto.embed) = true
];
ClusterAutoUpdateConfigSpecV1 Spec = 2 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "spec"
];
// Nonce is used to protect against concurrent modification of the maintenance
// window. Clients should treat nonces as opaque.
uint64 Nonce = 3 [(gogoproto.jsontag) = "nonce,omitempty"];
}

// ClusterAutoupdateConfigSpecV1 encodes the parameters of the autoupdate config object.
message ClusterAutoUpdateConfigSpecV1 {
// ToolsAutoUpdate encodes the feature flag to enable/disable tools autoupdates.
bool ToolsAutoUpdate = 1 [(gogoproto.jsontag) = "tools_auto_update,omitempty"];
}

// AutoupdateVersionV1 is a resource singleton with version required for
// tools autoupdate.
message AutoUpdateVersionV1 {
ResourceHeader Header = 1 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "",
(gogoproto.embed) = true
];
AutoupdateVersionSpecV1 Spec = 2 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "spec"
];
// Nonce is used to protect against concurrent modification of the maintenance
// window. Clients should treat nonces as opaque.
uint64 Nonce = 3 [(gogoproto.jsontag) = "nonce,omitempty"];
}

// AutoupdateVersionSpecV1 encodes the parameters of the autoupdate versions.
message AutoupdateVersionSpecV1 {
// ToolsVersion is the semantic version required for tools autoupdates.
string ToolsVersion = 1 [(gogoproto.jsontag) = "tools_version,omitempty"];
}

vapopov marked this conversation as resolved.
Show resolved Hide resolved
// ScheduledAgentUpgradeWindow is a derived value representing a single
// upgrade window. Upgraders deal with discrete start/end times, so we use the
// agent upgrade window configuration object to generate a sequence of specific
Expand Down
134 changes: 134 additions & 0 deletions api/types/autoupdate_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* 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 types

import (
"time"

"github.com/gravitational/teleport/api/utils"
"github.com/gravitational/trace"
)

// ClusterAutoUpdateConfig defines configuration of auto updates for tools and agents
type ClusterAutoUpdateConfig interface {
vapopov marked this conversation as resolved.
Show resolved Hide resolved
// Resource provides common resource properties.
Resource
// SetToolsAutoUpdate enables/disables tools autoupdate in the cluster.
SetToolsAutoUpdate(bool)
// GetToolsAutoUpdate gets feature flag if autoupdate is enabled in the cluster.
GetToolsAutoUpdate() bool
// Clone performs a deep copy.
Clone() ClusterAutoUpdateConfig
}

// NewClusterAutoUpdateConfig is a convenience wrapper to create a ClusterAutoupdateConfigV1 resource.
func NewClusterAutoUpdateConfig(spec ClusterAutoUpdateConfigSpecV1) (ClusterAutoUpdateConfig, error) {
resource := &ClusterAutoUpdateConfigV1{Spec: spec}
if err := resource.CheckAndSetDefaults(); err != nil {
return nil, trace.Wrap(err)
}
return resource, nil
}

// GetVersion returns resource version
func (c *ClusterAutoUpdateConfigV1) GetVersion() string {
return c.Version
}

// GetKind returns resource kind
func (c *ClusterAutoUpdateConfigV1) GetKind() string {
return c.Kind
}

// GetSubKind returns resource sub kind
func (c *ClusterAutoUpdateConfigV1) GetSubKind() string {
return c.SubKind
}

// SetSubKind sets resource subkind
func (c *ClusterAutoUpdateConfigV1) SetSubKind(sk string) {
c.SubKind = sk
}

// GetRevision returns the revision
func (c *ClusterAutoUpdateConfigV1) GetRevision() string {
return c.Metadata.GetRevision()
}

// SetRevision sets the revision
func (c *ClusterAutoUpdateConfigV1) SetRevision(rev string) {
c.Metadata.SetRevision(rev)
}

// GetName returns the name of the cluster autoupdate config.
func (c *ClusterAutoUpdateConfigV1) GetName() string {
return c.Metadata.Name
}

// SetName sets the name of the cluster autoupdate config.
func (c *ClusterAutoUpdateConfigV1) SetName(e string) {
c.Metadata.Name = e
}

// Expiry returns object expiry setting
func (c *ClusterAutoUpdateConfigV1) Expiry() time.Time {
return c.Metadata.Expiry()
}

// SetExpiry sets expiry time for the object
func (c *ClusterAutoUpdateConfigV1) SetExpiry(expires time.Time) {
c.Metadata.SetExpiry(expires)
}

// GetMetadata returns object metadata
func (c *ClusterAutoUpdateConfigV1) GetMetadata() Metadata {
return c.Metadata
}

// SetToolsAutoUpdate enables/disables tools autoupdate in the cluster.
func (c *ClusterAutoUpdateConfigV1) SetToolsAutoUpdate(flag bool) {
c.Spec.ToolsAutoUpdate = flag
}

// GetToolsAutoUpdate gets feature flag if autoupdate is enabled in the cluster.
func (c *ClusterAutoUpdateConfigV1) GetToolsAutoUpdate() bool {
return c.Spec.ToolsAutoUpdate
}

// Clone performs a deep copy.
func (c *ClusterAutoUpdateConfigV1) Clone() ClusterAutoUpdateConfig {
return utils.CloneProtoMsg(c)
}

// setStaticFields sets static resource header and metadata fields.
func (c *ClusterAutoUpdateConfigV1) setStaticFields() {
c.Kind = KindClusterAutoUpdateConfig
c.Version = V1
c.Metadata.Name = MetaNameClusterAutoUpdateConfig
}

// CheckAndSetDefaults checks validity of all parameters and sets defaults.
func (c *ClusterAutoUpdateConfigV1) CheckAndSetDefaults() error {
c.setStaticFields()
if err := c.Metadata.CheckAndSetDefaults(); err != nil {
return trace.Wrap(err)
}

return nil
}
138 changes: 138 additions & 0 deletions api/types/autoupdate_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* 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 types

import (
"github.com/gravitational/teleport/api/utils"
"time"

"github.com/gravitational/trace"
)

// AutoUpdateVersion defines resource for storing semantic version of auto updates.
type AutoUpdateVersion interface {
// Resource provides common resource properties.
Resource
// SetToolsVersion defines required version for tools autoupdate.
SetToolsVersion(string)
// GetToolsVersion gets last known required version for autoupdate.
GetToolsVersion() string
// Clone performs a deep copy.
Clone() AutoUpdateVersion
}

// NewAutoUpdateVersion is a convenience wrapper to create a AutoupdateVersionV1 resource.
func NewAutoUpdateVersion(spec AutoupdateVersionSpecV1) (AutoUpdateVersion, error) {
resource := &AutoUpdateVersionV1{Spec: spec}
if err := resource.CheckAndSetDefaults(); err != nil {
return nil, trace.Wrap(err)
}
return resource, nil
}

// GetVersion returns resource version
func (c *AutoUpdateVersionV1) GetVersion() string {
return c.Version
}

// GetKind returns resource kind
func (c *AutoUpdateVersionV1) GetKind() string {
return c.Kind
}

// GetSubKind returns resource sub kind
func (c *AutoUpdateVersionV1) GetSubKind() string {
return c.SubKind
}

// SetSubKind sets resource subkind
func (c *AutoUpdateVersionV1) SetSubKind(sk string) {
c.SubKind = sk
}

// GetRevision returns the revision
func (c *AutoUpdateVersionV1) GetRevision() string {
return c.Metadata.GetRevision()
}

// SetRevision sets the revision
func (c *AutoUpdateVersionV1) SetRevision(rev string) {
c.Metadata.SetRevision(rev)
}

// GetName returns the name of the autoupdate version.
func (c *AutoUpdateVersionV1) GetName() string {
return c.Metadata.Name
}

// SetName sets the name of the autoupdate version.
func (c *AutoUpdateVersionV1) SetName(e string) {
c.Metadata.Name = e
}

// Expiry returns object expiry setting
func (c *AutoUpdateVersionV1) Expiry() time.Time {
return c.Metadata.Expiry()
}

// SetExpiry sets expiry time for the object
func (c *AutoUpdateVersionV1) SetExpiry(expires time.Time) {
c.Metadata.SetExpiry(expires)
}

// GetMetadata returns object metadata
func (c *AutoUpdateVersionV1) GetMetadata() Metadata {
return c.Metadata
}

// SetToolsVersion defines required version for tools autoupdate.
func (c *AutoUpdateVersionV1) SetToolsVersion(version string) {
c.Spec.ToolsVersion = version
}

// GetToolsVersion gets last known required version for autoupdate.
func (c *AutoUpdateVersionV1) GetToolsVersion() string {
return c.Spec.ToolsVersion
}

// Clone performs a deep copy.
func (c *AutoUpdateVersionV1) Clone() AutoUpdateVersion {
return utils.CloneProtoMsg(c)
}

// setStaticFields sets static resource header and metadata fields.
func (c *AutoUpdateVersionV1) setStaticFields() {
c.Kind = KindAutoUpdateVersion
c.Version = V1
c.Metadata.Name = MetaNameAutoUpdateVersion
}

// CheckAndSetDefaults checks validity of all parameters and sets defaults.
func (c *AutoUpdateVersionV1) CheckAndSetDefaults() error {
c.setStaticFields()
if err := c.Metadata.CheckAndSetDefaults(); err != nil {
return trace.Wrap(err)
}

if c.Spec.ToolsVersion == "" {
return trace.BadParameter("missing ToolsVersion field")
}

return nil
}
12 changes: 12 additions & 0 deletions api/types/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,18 @@ const (
// alternative to their individual resource kinds.
KindClusterConfig = "cluster_config"

// KindClusterAutoUpdateConfig is the resource with cluster autoupdate configuration.
KindClusterAutoUpdateConfig = "cluster_autoupdate_config"

// KindAutoUpdateVersion is the resource with cluster autoupdate versions.
KindAutoUpdateVersion = "autoupdate_version"

// MetaNameClusterAutoUpdateConfig is the name of a configuration resource for cluster autoupdate config.
MetaNameClusterAutoUpdateConfig = "cluster-autoupdate-config"

// MetaNameAutoUpdateVersion is the name of a resource for autoupdate version.
MetaNameAutoUpdateVersion = "autoupdate-version"

// KindClusterAuditConfig is the resource that holds cluster audit configuration.
KindClusterAuditConfig = "cluster_audit_config"

Expand Down
Loading