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

security: add dry run mode for external cluster script #9189

Merged
merged 1 commit into from Dec 17, 2021

Conversation

subhamkrai
Copy link
Contributor

@subhamkrai subhamkrai commented Nov 17, 2021

Adding dry run mode for external cluster script.
This will add cli argument --dry-run. By default
dry-run option will be False
which means it will only print something like below.

Execute: 'ceph fs ls'
Execute: 'ceph fsid'
Execute: 'ceph quorum_status'
Execute: 'ceph auth get-or-create client.healthchecker mon allow r, allow command quorum_status, allow command version mgr allow command config osd allow rwx pool=default.rgw.meta, allow r pool=.rgw.root, allow rw pool=default.rgw.control, allow rx pool=default.rgw.log, allow x pool=default.rgw.buckets.index'
Execute: 'ceph mgr services'
Execute: 'ceph auth get-or-create client.csi-rbd-node mon profile rbd osd profile rbd'
Execute: 'ceph auth get-or-create client.csi-rbd-provisioner mon profile rbd mgr allow rw osd profile rbd'
Execute: 'ceph status'
None

Signed-off-by: subhamkrai srai@redhat.com

Description of your changes:

Which issue is resolved by this Pull Request:
Resolves #

Checklist:

  • Commit Message Formatting: Commit titles and messages follow guidelines in the developer guide.
  • Skip Tests for Docs: Add the flag for skipping the build if this is only a documentation change. See here for the flag.
  • Skip Unrelated Tests: Add a flag to run tests for a specific storage provider. See test options.
  • Reviewed the developer guide on Submitting a Pull Request
  • Documentation has been updated, if necessary.
  • Unit tests have been added, if necessary.
  • Integration tests have been added, if necessary.
  • Pending release notes updated with breaking and/or notable changes, if necessary.
  • Upgrade from previous release is tested and upgrade user guide is updated, if necessary.
  • Code generation (make codegen) has been run to update object specifications, if necessary.

@mergify
Copy link

mergify bot commented Nov 17, 2021

This pull request has merge conflicts that must be resolved before it can be merged. @subhamkrai please rebase it. https://rook.io/docs/rook/latest/development-flow.html#updating-your-fork

@subhamkrai subhamkrai force-pushed the readonly-external-script branch 2 times, most recently from c74f0f6 to b141fdf Compare November 17, 2021 05:37
@subhamkrai subhamkrai changed the title ceph: add read-only mode for external cluster script security: add read-only mode for external cluster script Nov 17, 2021
Copy link
Contributor

@aruniiird aruniiird left a comment

Choose a reason for hiding this comment

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

Current PR is simple and to the point. But I could see some short coming with this approach,

  • As the read-only mode is True by default, we will always end-up in an exception. Why because the functions we modified are called always by default.
  • Even if we could overcome the above^ issue (by adding conditions around the function calls), we have to make sure the lesser output (that is the subset of original output we get in a read-only mode) is good enough to connect to an external cluster.

I will suggest a bit more sophisticated/complex approach, where in place of get-or-create ceph api commands, we use a variable. This variable will be (by default) set to get and if read-only mode is False it will be set to get-or-create. Use this variable in places where we use cmd_json prefix get-or-create part.

Comment on lines 451 to 454
if self._arg_parser.read_only:
raise ExecutionFailureException(
"Read-only mode is enabled. Pass '--read-only' or '-r' as False")

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a common piece of code which is used. Can we convert it to a function, something like,

def raise_exception_if_read_only(self):
    if self._arg_parser.read_only:
        raise ExecutionFailureException(
            "Read-only mode is enabled. Pass '--read-only' or '-r' as False")

and call it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@leseb ^^

Copy link
Member

Choose a reason for hiding this comment

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

👍🏻

Copy link
Member

@leseb leseb left a comment

Choose a reason for hiding this comment

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

Based on previous discussions, we need to implement:

  • a dry-run functionality, so let's not call this read-only
  • make sure the script is idempotent and can run multiple times in a row

@mergify
Copy link

mergify bot commented Nov 30, 2021

This pull request has merge conflicts that must be resolved before it can be merged. @subhamkrai please rebase it. https://rook.io/docs/rook/latest/development-flow.html#updating-your-fork

@subhamkrai subhamkrai force-pushed the readonly-external-script branch 5 times, most recently from f440671 to ce97c27 Compare December 8, 2021 06:45
@subhamkrai
Copy link
Contributor Author

Based on previous discussions, we need to implement:

  • a dry-run functionality, so let's not call this read-only

for dry-run, currently, I'm just printing a message so that we don't get different outputs which were the case in read-only mode.

  • make sure the script is idempotent and can run multiple times in a row

@subhamkrai subhamkrai marked this pull request as ready for review December 8, 2021 06:49
Copy link
Member

@leseb leseb left a comment

Choose a reason for hiding this comment

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

A dry-run prints the command that would be executed if the dry-run was not set. You can print with a message too, just like you do now. If it's a ceph command, just print the command that would be executed too. Thanks

@subhamkrai subhamkrai force-pushed the readonly-external-script branch 2 times, most recently from bdf0003 to 12ae8dc Compare December 8, 2021 11:57
@subhamkrai subhamkrai requested a review from leseb December 8, 2021 11:58
Copy link
Member

@leseb leseb left a comment

Choose a reason for hiding this comment

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

We want to print the full command, without duplicating entries in the code. Also, the CI should test the dry-run too.

deploy/examples/create-external-cluster-resources.py Outdated Show resolved Hide resolved
@subhamkrai subhamkrai force-pushed the readonly-external-script branch 2 times, most recently from 1c12905 to 570055c Compare December 8, 2021 15:08
deploy/examples/create-external-cluster-resources.py Outdated Show resolved Hide resolved
deploy/examples/create-external-cluster-resources.py Outdated Show resolved Hide resolved
deploy/examples/create-external-cluster-resources.py Outdated Show resolved Hide resolved
deploy/examples/create-external-cluster-resources.py Outdated Show resolved Hide resolved
deploy/examples/create-external-cluster-resources.py Outdated Show resolved Hide resolved
deploy/examples/create-external-cluster-resources.py Outdated Show resolved Hide resolved
deploy/examples/create-external-cluster-resources.py Outdated Show resolved Hide resolved
deploy/examples/create-external-cluster-resources.py Outdated Show resolved Hide resolved
deploy/examples/create-external-cluster-resources.py Outdated Show resolved Hide resolved
deploy/examples/create-external-cluster-resources.py Outdated Show resolved Hide resolved
@subhamkrai subhamkrai changed the title security: add read-only mode for external cluster script security: add dry run mode for external cluster script Dec 10, 2021
@mergify
Copy link

mergify bot commented Dec 14, 2021

This pull request has merge conflicts that must be resolved before it can be merged. @subhamkrai please rebase it. https://rook.io/docs/rook/latest/development-flow.html#updating-your-fork

Copy link
Member

@parth-gr parth-gr left a comment

Choose a reason for hiding this comment

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

we can add a simple unit test for it,
Rest looks good to me.

@leseb
Copy link
Member

leseb commented Dec 14, 2021

@subhamkrai
Copy link
Contributor Author

@subhamkrai CI is failing https://github.com/rook/rook/runs/4520799129?check_suite_focus=true PTAL

the error says Execution Failed: The provided pool, 'replicapool', does not exist and

1 device_health_metrics
2 ec-pool
3 .nfs
4 my-store.rgw.buckets.index
5 my-store.rgw.buckets.non-ec
6 my-store.rgw.control
7 my-store.rgw.meta
8 my-store.rgw.log
9 .rgw.root
10 myfs-metadata
11 my-store.rgw.buckets.data
12 myfs-data0

this also says replicapool doesn't exist but we are creating that

cephblockpool.ceph.rook.io/replicapool created
+ kubectl create -f pool-ec.yaml
cephblockpool.ceph.rook.io/ec-pool created```

I also noticed that once earlier but the error went away after I pushed latest changes 

@subhamkrai
Copy link
Contributor Author

I was not able to check op logs due to timeout

Copy link
Member

@parth-gr parth-gr left a comment

Choose a reason for hiding this comment

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

I was not able to check op logs due to timeout

you can run external script unit test locally python3 -m unittest --verbose <script_name_without_dot_py>.

PS: ohh the actual run is failing

@parth-gr parth-gr self-requested a review December 14, 2021 15:03
@subhamkrai
Copy link
Contributor Author

I was not able to check op logs due to timeout

you can run external script unit test locally python3 -m unittest --verbose <script_name_without_dot_py>.

PS: ohh the actual run is failing

locally it is running

@mergify
Copy link

mergify bot commented Dec 15, 2021

This pull request has merge conflicts that must be resolved before it can be merged. @subhamkrai please rebase it. https://rook.io/docs/rook/latest/development-flow.html#updating-your-fork

Adding dry run mode for external cluster script.
This will add cli argument `--dry-run`. By default
`dry-run` option will be `False`
which means it will only print something like below.

```
Execute: 'ceph fs ls'
Execute: 'ceph fsid'
Execute: 'ceph quorum_status'
Execute: 'ceph auth get-or-create client.healthchecker mon allow r, allow command quorum_status,
	allow command version mgr allow command config osd allow rwx pool=default.rgw.meta, allow r pool=
	.rgw.root, allow rw pool=default.rgw.control, allow rx pool=default.rgw.log, allow x
	pool=default.rgw.buckets.index'
Execute: 'ceph mgr services'
Execute: 'ceph auth get-or-create client.csi-rbd-node mon profile rbd osd profile rbd'
Execute: 'ceph auth get-or-create client.csi-rbd-provisioner mon profile rbd mgr allow rw osd
	profile rbd'
Execute: 'ceph status'

```

Signed-off-by: subhamkrai <srai@redhat.com>
@subhamkrai
Copy link
Contributor Author

Since we remove the external ec test from the canary test. We should be good now and later we can discuss how we can add the removed test. Comment

Copy link
Member

@leseb leseb left a comment

Choose a reason for hiding this comment

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

The output is missing the cephfs keyring, only rbd is present:

Execute: 'ceph auth get-or-create client.csi-rbd-node mon profile rbd osd profile rbd'
Execute: 'ceph auth get-or-create client.csi-rbd-provisioner mon profile rbd mgr allow rw osd profile rbd'

@subhamkrai
Copy link
Contributor Author

The output is missing the cephfs keyring, only rbd is present:

Execute: 'ceph auth get-or-create client.csi-rbd-node mon profile rbd osd profile rbd'
Execute: 'ceph auth get-or-create client.csi-rbd-provisioner mon profile rbd mgr allow rw osd profile rbd'

I think it depends on what argument we are passing with --dry-run and currently in this CI I'm passing only --rbd-data-pool-name that's why only rbd commands only.

@leseb leseb dismissed aruniiird’s stale review December 17, 2021 07:50

comments addressed

@leseb leseb merged commit 97978b5 into rook:master Dec 17, 2021
mergify bot added a commit that referenced this pull request Dec 17, 2021
security: add dry run mode for external cluster script (backport #9189)
@subhamkrai subhamkrai deleted the readonly-external-script branch December 17, 2021 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants