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

[SR] Prevent change to snapshot name / repository for managed SLM policies #172291

Merged
merged 7 commits into from
Dec 12, 2023

Conversation

renshuki
Copy link
Contributor

@renshuki renshuki commented Nov 30, 2023

Summary

Managed SLM policies Snapshot name and Repository field values can be changed from the Snapshot and Restore UI. This is particularly an issue with the cloud-snapshot-policy as changes to the snapshot name or target repository will lead to plan failures on ESS. Besides having a warning message displayed for managed SLM policies:

This is a managed policy. Changing this policy might affect other systems that use it. Proceed with caution.
field values being editable is prone to errors.

This PR disable the Snapshot name and Repository field for managed SLM policies to prevent edits.

Example - Regular SLM policy:
Untitled2

Example - Managed SLM policy:
Untitled

I'm open to suggestions if there is a better way to do this.

This PR fixes #124916

Checklist

For maintainers

Release Note

Input fields to change snapshot name and repository are now disabled when editing managed SLM policies in Snapshot & Restore.

@renshuki renshuki requested a review from a team as a code owner November 30, 2023 14:18
@renshuki renshuki added Feature:Snapshot and Restore Elasticsearch snapshots and repositories UI Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more labels Nov 30, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/platform-deployment-management (Team:Deployment Management)

@yuliacech yuliacech self-requested a review November 30, 2023 17:14
@yuliacech yuliacech added the ci:cloud-deploy Create or update a Cloud deployment label Nov 30, 2023
@yuliacech yuliacech added the release_note:skip Skip the PR/issue when compiling release notes label Nov 30, 2023
Copy link
Contributor

@yuliacech yuliacech left a comment

Choose a reason for hiding this comment

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

Thanks a lot for raising a PR for this issue, @renshuki!
Even though the proposed change is straight forward, I think there are still some things to discuss:

  • It looks like changing managed repos/policies on Cloud can lead to serious issues for the deployment. Should we consider first disabling the changes on the ES/Control plane side? Even with some UI elements disabled for managed policies, users will still be able to change the repo/policy via Console for example.
  • The issue links to the docs that warns the user of changing the repo found-snapshots and the policy cloud-snapshot-policy. So should we only disable editing for those items specifically or do we want to rely on the managed: true property?
  • Instead of disabling snapshot name and repo in the policy edit form, should we consider disabling the edit form all together?
  • Should we also consider similar changes for the repo found-snapshots?

Let me know what you think @renshuki, also tagging @alisonelizabeth and @sixstringcode for their input.

@renshuki
Copy link
Contributor Author

renshuki commented Dec 1, 2023

@yuliacech thank you for raising these questions.

It looks like changing managed repos/policies on Cloud can lead to serious issues for the deployment.

Correct, that why I wanted to implement this change primarily.

Should we consider first disabling the changes on the ES/Control plane side? Even with some UI elements disabled for managed policies, users will still be able to change the repo/policy via Console for example.

You are right, some server side validation / limit the scope of editable fields for managed SLM policies via API would be worth discussing with ES / Control Plane.

The issue links to the docs that warns the user of changing the repo found-snapshots and the policy cloud-snapshot-policy. So should we only disable editing for those items specifically or do we want to rely on the managed: true property?

I'm not aware of any other Elastic product defining a managed SLM policy other than Cloud. Also, I don't see a scenario where the snapshot name or repository for a managed SLM policy need to be configurable by the end user. That's why I kept this "generic" approach with isManaged: true.

Instead of disabling snapshot name and repo in the policy edit form, should we consider disabling the edit form all together?

No, the reason is that users should still have the possibility to customize the schedule and retention period for the snapshots.

Should we also consider similar changes for the repo found-snapshots?

I agree, for managed Repositories, preventing changes to Client, Bucket and Base Path fields via the UI would make sense. Maybe we want to tackle this part in a different Kibana issue / PR. Similar to what you mentioned above, I can also raise an issue for ES / Control Plan to see if we need to put some restrictions for managed Respositories related APIs - but Cloud may want to keep a cerain level of flexibility in the case of repositories (for example, scenarios where a S3 bucket need to be recreated)

My thought was that disabling fields in the UI would be "good enough" to mitigate most user errors with little time investment.

Copy link
Contributor

@yuliacech yuliacech left a comment

Choose a reason for hiding this comment

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

Thanks a lot for providing the context, @renshuki!
Would you be able to start the conversation about limiting changes on the backend with the ES and the Control plane teams please? I don't think our team has enough details to do that. Also could you please open an issue about similar UI work needed for the repository edit form?
To get this PR merged, we need to add some integration tests, there is an example here, the mock policy would need to be a managed policy. If that is difficult, let me know and I could add the tests directly to your branch.

@alisonelizabeth
Copy link
Contributor

Thank you @renshuki and @yuliacech for the discussion on this.

I agree with Yulia that it would be preferred to enforce this at the API layer rather than only putting in controls on the client side. @renshuki please let us know if you are able to start a conversation around that. I'm OK to proceed with this as a partial fix for now, as this appears to be causing a number of customer issues.

To get this PR merged, we need to add some integration tests, there is an example here, the mock policy would need to be a managed policy.

++ please let us know if you need help here

@renshuki
Copy link
Contributor Author

renshuki commented Dec 4, 2023

Thank you @yuliacech, @alisonelizabeth for your comments / feedback.
Below, a recap of the items that need to be addressed:

@renshuki
Copy link
Contributor Author

renshuki commented Dec 8, 2023

@yuliacech sorry, I need some guidance for the integration tests. I'm wondering if we want to keep it simple by modifying the the current mock policy like adding isManagedPolicy: true to POLICY_EDIT in constants.ts:

export const POLICY_EDIT = getPolicy({
name: POLICY_NAME,
retention: { minCount: 1 },
config: { includeGlobalState: true, featureStates: ['kibana'] },
});

and then add some tests in policy_edit.test.ts like:

    test('should disable the snapshot name field for managed policy', () => {
      const { find } = testBed;

      const snapshotNameInput = find('snapshotNameInput');
      expect(snapshotNameInput.props().disabled).toEqual(true);
    });

    test('should disable the respository select field for managed policy', () => {
      const { find } = testBed;

      const repositorySelect = find('repositorySelect');
      expect(repositorySelect.props().disabled).toEqual(true);
    });

or should we treat managed SLM policy tests in a completely different integration test file / mock policy?

@yuliacech
Copy link
Contributor

@renshuki I would add a new test to this file with a mock that uses the existing policy that you linked, but changes the data only for this test. I could just push my suggestion to your branch, if this PR is open to be updated by maintainers, if that's okay for you?

@yuliacech
Copy link
Contributor

Here is the code suggestion

test('should disable the repo and snapshot fields for managed policies', async () => {
      httpRequestsMockHelpers.setGetPolicyResponse(POLICY_EDIT.name, {
        policy: {
          ...POLICY_EDIT,
          isManagedPolicy: true,
        },
      });

      await act(async () => {
        testBed = await setup(httpSetup);
      });
      testBed.component.update();

      const { find } = testBed;

      const snapshotInput = find('snapshotNameInput');
      expect(snapshotInput.props().disabled).toEqual(true);

      const repoSelect = find('repositorySelect');
      expect(repoSelect.props().disabled).toEqual(true);
    });

@renshuki
Copy link
Contributor Author

renshuki commented Dec 9, 2023

Thank you @yuliacech for the code suggestion 😃 Please, feel free to push it to the feat-slm-managed-policy-ui-nomodify branch 🙏

@yuliacech
Copy link
Contributor

Thanks @renshuki! I pushed a commit with the test and with this, I'm good with merging this PR if you want to add the tooltip in a separate PR.

@yuliacech yuliacech removed the ci:cloud-deploy Create or update a Cloud deployment label Dec 11, 2023
@renshuki
Copy link
Contributor Author

LGTM @yuliacech, please feel free to merge. I opened #173124 separetely for the tooltips. I assigned it to me and will do the implementation in a different PR.

To circle back around the discussion with Elasticsearch / Control Plane to restrict APIs, they want to "keep an escape hatch for unforeseen situations where they must be changed" - but they may reconsider in the future:
elastic/elasticsearch#103066 (comment)

@yuliacech yuliacech enabled auto-merge (squash) December 12, 2023 10:31
@yuliacech yuliacech merged commit f2ca740 into main Dec 12, 2023
36 of 37 checks passed
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #3 / APM API tests alerts/transaction_duration.spec.ts basic no archive transaction duration alert create rule for opbeans-node using kql filter shows alert count=1 for opbeans-node on service inventory

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
snapshotRestore 259.6KB 259.7KB +94.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@yuliacech yuliacech deleted the feat-slm-managed-policy-ui-nomodify branch December 12, 2023 12:53
@kibanamachine kibanamachine added v8.13.0 backport:skip This commit does not require backporting labels Dec 12, 2023
@yuliacech yuliacech added release_note:fix and removed release_note:skip Skip the PR/issue when compiling release notes labels Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Snapshot and Restore Elasticsearch snapshots and repositories UI release_note:fix Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v8.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prevent some fields to be edited in SLM managed policies
6 participants