Skip to content

Conversation

Mhodesty
Copy link

Initial working version of protected labels for the rhobs API. This prevents users from manually patching these values.

% curl -s -X PATCH -H "Content-Type: application/json" \\n  -d '{"status": "active"}' \\n  http://localhost:8081/probes/39d4faed-d0f4-46d2-86f3-114662102d6a
{"error":{"message":"modification of status field is forbidden - it's managed by the system (only deletion via 'deleted' status is allowed)"}}

@openshift-ci openshift-ci bot requested review from aliceh and moadz September 24, 2025 17:04
Copy link

openshift-ci bot commented Sep 24, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Mhodesty

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

codecov bot commented Sep 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.95%. Comparing base (0770693) to head (afe352c).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #94      +/-   ##
==========================================
+ Coverage   61.44%   62.95%   +1.51%     
==========================================
  Files           6        6              
  Lines         708      737      +29     
==========================================
+ Hits          435      464      +29     
  Misses        232      232              
  Partials       41       41              
Files with missing lines Coverage Δ
internal/api/server.go 80.47% <100.00%> (+4.04%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@jimdaga jimdaga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a few PR nits.

I also noticed tests are failing because of rpms-signature-scan errors.
I think we already fixed that on main (had to merge a PR) - you may need to rebase?

Comment on lines 59 to 75
// validateProtectedFields checks if the user is trying to modify protected fields/labels
func validateProtectedFields(request *v1.UpdateProbeJSONRequestBody) error {
// Check if user is trying to modify protected labels
if err := validateProtectedLabels(request.Labels); err != nil {
return err
}

// Check if user is trying to modify status (except for deletion)
if request.Status != nil {
// Only allow status change to "deleted" for deletion functionality
if *request.Status != v1.Deleted {
return fmt.Errorf("modification of status field is forbidden - it's managed by the system (only deletion via 'deleted' status is allowed)")
}
}

return nil
}
Copy link
Collaborator

@jimdaga jimdaga Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modifying the "status" data object IS allowed.

We want to let RMO set a terminating status and the Synthetic Agent changes state to active / failed.

It's only the status label: that we're concerned about protecting, and you did that above (aka: probeStatusLabelKey).

It's a little confusing, but you'll see:

  • "status": "active" in the `probe-config.json - this is the thing we want to allow to be modified.
  • rhobs-synthetics/status: active in the labels: - that's what we're protecting.
ocm backplane elevate "SREP-333" -- get cm -n rhobs-int probe-config-4dd39ee5-42d1-45cc-8b5c-49b1fd8907dc -o yaml
apiVersion: v1
data:
  probe-config.json: '{"id":"4dd39ee5-42d1-45cc-8b5c-49b1fd8907dc","labels":{"cluster-id":"361327b1-5a11-4f06-b75f-268ba6e99dcc","private":"false","tenant":"hcp"},"static_url":"https://api.cs-ci-m7dqj.af4m.i3.devshift.org/livez","status":"active"}'
kind: ConfigMap
metadata:
  creationTimestamp: "2025-09-16T01:20:45Z"
  labels:
    app: rhobs-synthetics-probe
    cluster-id: 361327b1-5a11-4f06-b75f-268ba6e99dcc
    private: "false"
    rhobs-synthetics/static-url-hash: 47d80a225655474a41c076ff2f21fe6c940f93a8e3c848b08bc341afa0ebce0
    rhobs-synthetics/status: active
    tenant: hcp
  name: probe-config-4dd39ee5-42d1-45cc-8b5c-49b1fd8907dc
  namespace: rhobs-int
  resourceVersion: "119427894"
  uid: 407d596d-17a8-4985-9441-689ef1c169d8

TLDR; We don't need validateProtectedFields()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Jim.
I know this is a few weeks old but could you explain what you mean here because I am confused.

You're saying that you want us to still be able to run patch commands on the API to change the status of the probe, but you want me to put something in place so the configMap can't be modified?

defer metrics.RecordProbestoreRequest("update_probe", time.Now())

// Validate that protected fields/labels are not being modified - return 403 if they are
if err := validateProtectedFields(request.Body); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be updated to only call validateProtectedLabels()

}

// Now, update the fields from the request.
// Handle status updates (only "deleted" is allowed, validated above)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert

Copy link

openshift-ci bot commented Oct 9, 2025

@Mhodesty: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/coverage a130d34 link true /test coverage
ci/prow/test a130d34 link true /test test

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants