Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit140768f

Browse files
cstyanclaude
andcommitted
Add deployment-wide agent metadata minimum interval enforcement
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent05b02cf commit140768f

File tree

12 files changed

+512
-2
lines changed

12 files changed

+512
-2
lines changed

‎cli/testdata/coder_server_--help.golden‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ SUBCOMMANDS:
1414
PostgreSQL deployment.
1515

1616
OPTIONS:
17+
--agent-metadata-min-interval duration, $CODER_AGENT_METADATA_MIN_INTERVAL (default: 0s)
18+
Minimum interval for agent metadata collection. Template-defined
19+
intervals below this value will cause template import to fail.
20+
Existing workspaces with lower intervals will be silently upgraded on
21+
restart. Set to 0 to disable enforcement.
22+
1723
--allow-workspace-renames bool, $CODER_ALLOW_WORKSPACE_RENAMES (default: false)
1824
DEPRECATED: Allow users to rename their workspaces. Use only for
1925
temporary compatibility reasons, this will be removed in a future

‎cli/testdata/server-config.yaml.golden‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,11 @@ sshKeygenAlgorithm: ed25519
485485
# URL to use for agent troubleshooting when not set in the template.
486486
# (default: https://coder.com/docs/admin/templates/troubleshooting, type: url)
487487
agentFallbackTroubleshootingURL: https://coder.com/docs/admin/templates/troubleshooting
488+
# Minimum interval for agent metadata collection. Template-defined intervals below
489+
# this value will cause template import to fail. Existing workspaces with lower
490+
# intervals will be silently upgraded on restart. Set to 0 to disable enforcement.
491+
# (default: 0s, type: duration)
492+
agentMetadataMinInterval: 0s
488493
# Disable workspace apps that are not served from subdomains. Path-based apps can
489494
# make requests to the Coder API and pose a security risk when the workspace
490495
# serves malicious JavaScript. This is recommended for security purposes if a

‎coderd/apidoc/docs.go‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/apidoc/swagger.json‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/provisionerdserver/provisionerdserver.go‎

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,7 +1613,11 @@ func (s *server) completeTemplateImportJob(ctx context.Context, job database.Pro
16131613
slog.F("resource_type",resource.Type),
16141614
slog.F("transition",transition))
16151615

1616-
iferr:=InsertWorkspaceResource(ctx,db,jobID,transition,resource,telemetrySnapshot);err!=nil {
1616+
iferr:=InsertWorkspaceResource(ctx,db,jobID,transition,resource,telemetrySnapshot,
1617+
InsertWorkspaceResourceWithValidationMode(ValidationModeStrict),
1618+
InsertWorkspaceResourceWithDeploymentValues(s.DeploymentValues),
1619+
InsertWorkspaceResourceWithLogger(s.Logger),
1620+
);err!=nil {
16171621
returnxerrors.Errorf("insert resource: %w",err)
16181622
}
16191623
}
@@ -2014,6 +2018,9 @@ func (s *server) completeWorkspaceBuildJob(ctx context.Context, job database.Pro
20142018
// Ensure that the agent IDs we set previously
20152019
// are written to the database.
20162020
InsertWorkspaceResourceWithAgentIDsFromProto(),
2021+
InsertWorkspaceResourceWithValidationMode(ValidationModeUpgrade),
2022+
InsertWorkspaceResourceWithDeploymentValues(s.DeploymentValues),
2023+
InsertWorkspaceResourceWithLogger(s.Logger),
20172024
)
20182025
iferr!=nil {
20192026
returnxerrors.Errorf("insert provisioner job: %w",err)
@@ -2623,8 +2630,23 @@ func InsertWorkspacePresetAndParameters(ctx context.Context, db database.Store,
26232630
returnnil
26242631
}
26252632

2633+
// ValidationMode determines how agent metadata interval validation is enforced.
2634+
typeValidationModeint
2635+
2636+
const (
2637+
// ValidationModeStrict fails the operation if metadata intervals are below the minimum.
2638+
// Used for template imports.
2639+
ValidationModeStrictValidationMode=iota
2640+
// ValidationModeUpgrade silently upgrades metadata intervals to meet the minimum.
2641+
// Used for workspace builds.
2642+
ValidationModeUpgrade
2643+
)
2644+
26262645
typeinsertWorkspaceResourceOptionsstruct {
26272646
useAgentIDsFromProtobool
2647+
validationModeValidationMode
2648+
deploymentValues*codersdk.DeploymentValues
2649+
logger slog.Logger
26282650
}
26292651

26302652
// InsertWorkspaceResourceOption represents a functional option for
@@ -2639,6 +2661,27 @@ func InsertWorkspaceResourceWithAgentIDsFromProto() InsertWorkspaceResourceOptio
26392661
}
26402662
}
26412663

2664+
// InsertWorkspaceResourceWithValidationMode sets the validation mode for agent metadata intervals.
2665+
funcInsertWorkspaceResourceWithValidationMode(modeValidationMode)InsertWorkspaceResourceOption {
2666+
returnfunc(opts*insertWorkspaceResourceOptions) {
2667+
opts.validationMode=mode
2668+
}
2669+
}
2670+
2671+
// InsertWorkspaceResourceWithDeploymentValues sets the deployment values for validation.
2672+
funcInsertWorkspaceResourceWithDeploymentValues(dv*codersdk.DeploymentValues)InsertWorkspaceResourceOption {
2673+
returnfunc(opts*insertWorkspaceResourceOptions) {
2674+
opts.deploymentValues=dv
2675+
}
2676+
}
2677+
2678+
// InsertWorkspaceResourceWithLogger sets the logger for logging validation actions.
2679+
funcInsertWorkspaceResourceWithLogger(logger slog.Logger)InsertWorkspaceResourceOption {
2680+
returnfunc(opts*insertWorkspaceResourceOptions) {
2681+
opts.logger=logger
2682+
}
2683+
}
2684+
26422685
funcInsertWorkspaceResource(ctx context.Context,db database.Store,jobID uuid.UUID,transition database.WorkspaceTransition,protoResource*sdkproto.Resource,snapshot*telemetry.Snapshot,opt...InsertWorkspaceResourceOption)error {
26432686
opts:=&insertWorkspaceResourceOptions{}
26442687
for_,o:=rangeopt {
@@ -2776,13 +2819,39 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
27762819
snapshot.WorkspaceAgents=append(snapshot.WorkspaceAgents,telemetry.ConvertWorkspaceAgent(dbAgent))
27772820

27782821
for_,md:=rangeprAgent.Metadata {
2822+
interval:=md.Interval
2823+
2824+
// Apply minimum interval validation if configured
2825+
ifopts.deploymentValues!=nil&&opts.deploymentValues.AgentMetadataMinInterval.Value()>0 {
2826+
minInterval:=opts.deploymentValues.AgentMetadataMinInterval.Value()
2827+
minIntervalSeconds:=int64(minInterval.Seconds())
2828+
2829+
ifinterval<minIntervalSeconds {
2830+
ifopts.validationMode==ValidationModeStrict {
2831+
// Template import - fail the operation
2832+
returnxerrors.Errorf(
2833+
"agent %q metadata %q interval %ds is below minimum required %ds",
2834+
prAgent.Name,md.Key,interval,minIntervalSeconds,
2835+
)
2836+
}
2837+
// Workspace build - upgrade silently
2838+
opts.logger.Info(ctx,"upgrading agent metadata interval to meet minimum",
2839+
slog.F("agent",prAgent.Name),
2840+
slog.F("metadata_key",md.Key),
2841+
slog.F("original_interval_seconds",interval),
2842+
slog.F("upgraded_interval_seconds",minIntervalSeconds),
2843+
)
2844+
interval=minIntervalSeconds
2845+
}
2846+
}
2847+
27792848
p:= database.InsertWorkspaceAgentMetadataParams{
27802849
WorkspaceAgentID:agentID,
27812850
DisplayName:md.DisplayName,
27822851
Script:md.Script,
27832852
Key:md.Key,
27842853
Timeout:md.Timeout,
2785-
Interval:md.Interval,
2854+
Interval:interval,
27862855
// #nosec G115 - Order represents a display order value that's always small and fits in int32
27872856
DisplayOrder:int32(md.Order),
27882857
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp