-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add autoupdate agent type validations (#47831)
* Add autoupdate agent validations * Add AutoUpdateAgentRollout constants * Fix autoupdate API licenses Teleport's `api/` and `integrations/` should be Apache-licensed. Only the main teleport process should be licenses under AGPLv3. * address feedback
- Loading branch information
Showing
9 changed files
with
651 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
Copyright 2024 Gravitational, Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package autoupdate | ||
|
||
const ( | ||
// ToolsUpdateModeEnabled enables client tools automatic updates. | ||
ToolsUpdateModeEnabled = "enabled" | ||
// ToolsUpdateModeDisabled disables client tools automatic updates. | ||
ToolsUpdateModeDisabled = "disabled" | ||
|
||
// AgentsUpdateModeEnabled enabled agent automatic updates. | ||
AgentsUpdateModeEnabled = "enabled" | ||
// AgentsUpdateModeDisabled disables agent automatic updates. | ||
AgentsUpdateModeDisabled = "disabled" | ||
// AgentsUpdateModeSuspended temporarily suspends agent automatic updates. | ||
AgentsUpdateModeSuspended = "suspended" | ||
|
||
// AgentsScheduleRegular is the regular agent update schedule. | ||
AgentsScheduleRegular = "regular" | ||
// AgentsScheduleImmediate is the immediate agent update schedule. | ||
// Every agent must update immediately if it's not already running the target version. | ||
// This can be used to recover agents in case of major incident or actively exploited vulnerability. | ||
AgentsScheduleImmediate = "immediate" | ||
|
||
// AgentsStrategyHaltOnError is the agent update strategy that updates groups sequentially | ||
// according to their order in the schedule. The previous groups must succeed. | ||
AgentsStrategyHaltOnError = "halt-on-error" | ||
// AgentsStrategyTimeBased is the agent update strategy that updates groups solely based on their | ||
// maintenance window. There is no dependency between groups. Agents won't be instructed to update | ||
// if the window is over. | ||
AgentsStrategyTimeBased = "time-based" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
Copyright 2024 Gravitational, Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
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" | ||
) | ||
|
||
// NewAutoUpdateAgentRollout creates a new auto update version resource. | ||
func NewAutoUpdateAgentRollout(spec *autoupdate.AutoUpdateAgentRolloutSpec) (*autoupdate.AutoUpdateAgentRollout, error) { | ||
version := &autoupdate.AutoUpdateAgentRollout{ | ||
Kind: types.KindAutoUpdateAgentRollout, | ||
Version: types.V1, | ||
Metadata: &headerv1.Metadata{ | ||
Name: types.MetaNameAutoUpdateAgentRollout, | ||
}, | ||
Spec: spec, | ||
} | ||
if err := ValidateAutoUpdateAgentRollout(version); err != nil { | ||
return nil, trace.Wrap(err) | ||
} | ||
|
||
return version, nil | ||
} | ||
|
||
// ValidateAutoUpdateAgentRollout checks that required parameters are set | ||
// for the specified AutoUpdateAgentRollout. | ||
func ValidateAutoUpdateAgentRollout(v *autoupdate.AutoUpdateAgentRollout) error { | ||
if v == nil { | ||
return trace.BadParameter("AutoUpdateAgentRollout is nil") | ||
} | ||
if v.Metadata == nil { | ||
return trace.BadParameter("Metadata is nil") | ||
} | ||
if v.Metadata.Name != types.MetaNameAutoUpdateAgentRollout { | ||
return trace.BadParameter("Name is not valid") | ||
} | ||
if v.Spec == nil { | ||
return trace.BadParameter("Spec is nil") | ||
} | ||
if err := checkVersion(v.Spec.StartVersion); err != nil { | ||
return trace.Wrap(err, "validating spec.start_version") | ||
} | ||
if err := checkVersion(v.Spec.TargetVersion); err != nil { | ||
return trace.Wrap(err, "validating spec.target_version") | ||
} | ||
if err := checkAgentsMode(v.Spec.AutoupdateMode); err != nil { | ||
return trace.Wrap(err, "validating spec.autoupdate_mode") | ||
} | ||
if err := checkScheduleName(v.Spec.Schedule); err != nil { | ||
return trace.Wrap(err, "validating spec.schedule") | ||
} | ||
if err := checkAgentsStrategy(v.Spec.Strategy); err != nil { | ||
return trace.Wrap(err, "validating spec.strategy") | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.