Skip to content

Adding oc_adm_csr to lib_openshift for node approvals - #5112

Merged
sdodson merged 1 commit into
openshift:masterfrom
kwoodson:oc_adm_csr
Aug 23, 2017
Merged

sdodson merged 1 commit into
openshift:masterfrom
kwoodson:oc_adm_csr

Conversation

@kwoodson

@kwoodson kwoodson commented Aug 17, 2017 •

Copy link
Copy Markdown
Contributor

This pull request coincides with the node bootstrapping. I have introduced oc_adm_csr.py to the lib_openshift modules. This allows us to approve nodes in an automated fashion. I have added a few parameters in attempt to facilitate auto acceptance.

  • Added a timeout in case waiting takes forever.
  • Added a parameter for a node list so that we can pass in an expected list of nodes that should be approved
  • Added a flag to approve_all nodes. This is more for testing.

@kwoodson
kwoodson requested review from ashcrow and removed request for ashcrow August 17, 2017 01:19
@kwoodson

Copy link
Copy Markdown
Contributor Author

aos-ci-test

@openshift-bot

Copy link
Copy Markdown

success: "aos-ci-jenkins/OS_3.6_NOT_containerized, aos-ci-jenkins/OS_3.6_NOT_containerized_e2e_tests" for dabaf2c (logs)

@openshift-bot

Copy link
Copy Markdown

success: "aos-ci-jenkins/OS_3.6_containerized, aos-ci-jenkins/OS_3.6_containerized_e2e_tests" for dabaf2c (logs)

@ashcrow

ashcrow commented Aug 17, 2017 •

Copy link
Copy Markdown
Member

From Travis:

************* Module oc_adm_csr

roles/lib_openshift/library/oc_adm_csr.py:163: [E0602(undefined-variable), OpenShiftCLI._replace_content] Undefined variable 'Yedit'

roles/lib_openshift/library/oc_adm_csr.py:181: [E0602(undefined-variable), OpenShiftCLI._replace] Undefined variable 'Yedit'

roles/lib_openshift/library/oc_adm_csr.py:194: [E0602(undefined-variable), OpenShiftCLI._create_from_content] Undefined variable 'Yedit'

roles/lib_openshift/library/oc_adm_csr.py:241: [E0602(undefined-variable), OpenShiftCLI._process] Undefined variable 'Yedit'

roles/lib_openshift/library/oc_adm_csr.py:720: [R0913(too-many-arguments), OCcsr.__init__] Too many arguments (6/5)

roles/lib_openshift/library/oc_adm_csr.py:764: [R0201(no-self-use), OCcsr.action_needed] Method could be a function

roles/lib_openshift/library/oc_adm_csr.py:36: [W0611(unused-import), ] Unused import copy

roles/lib_openshift/library/oc_adm_csr.py:39: [W0611(unused-import), ] Unused import re

if nodes is None:
return nodes_list


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Extra spacing here. Likely flake8 will complain.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

got it!

timeout = True
break

time.sleep(2)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I recommend adding a comment on why sleep is needed. Not required, but I think it would be helpful.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

will do

required: false
default: None
aliases: []
author:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Missing docs for timeout, approve_all, service_account.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah, realized that last night when I pushed.

# TODO RECONCILE NODES ALREADY IN CLUSTER

# no nodes were passed and we are accepting everything. Keep going
if self.approve_all and len(self.nodes) == 0:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this could be simplified with:

# If nodes is set and it has contents then return specific data
if self.nodes is not None and len(self.nodes) > 0:
    return all([node['accepted'] for node in self.nodes])

# Otherwise we don't have any node data to return
return False

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

looks good. Simplify the logic

@kwoodson
kwoodson force-pushed the oc_adm_csr branch 3 times, most recently from e1e0ec3 to 4556fb7 Compare August 18, 2017 03:01
@kwoodson

Copy link
Copy Markdown
Contributor Author

aos-ci-test

@kwoodson

Copy link
Copy Markdown
Contributor Author

@ashcrow ready for review again, please.

@openshift-bot

Copy link
Copy Markdown

success: "aos-ci-jenkins/OS_3.6_containerized, aos-ci-jenkins/OS_3.6_containerized_e2e_tests" for 4556fb7 (logs)

@openshift-bot

Copy link
Copy Markdown

success: "aos-ci-jenkins/OS_3.6_NOT_containerized, aos-ci-jenkins/OS_3.6_NOT_containerized_e2e_tests" for 4556fb7 (logs)

@kwoodson
kwoodson requested a review from ashcrow August 18, 2017 19:54
# if approve_all, then do it
# if you passed in nodes, you must have a node that matches
if self.approve_all or (node and OCcsr.action_needed(csr, action)):
result = self.openshift_cmd(['certificate', action, csr['metadata']['name']], oadm=True)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If this ends up having an action of denied should the node still be accepted and returned in the results?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I need to test with 'deny'.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ashcrow, I added a couple of statements to exit when the deny flag was passed. I'm not in love with this method but the acceptance can be quite complex and in the future will be handled by the cloud-provider/k8s. This script is meant to be temporary until something comes into the product to support the same functionality.

@ashcrow ashcrow Aug 21, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@kwoodson I'm not seeing where the exit is occurring. Mind pointing it out for me?
I found it.

@ashcrow ashcrow Aug 21, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If action is set to denied, nodeis populated,OCcsr.action_needed(csr, action))is called noting action is needed todeny.... doesn't line 128 still set the node toaccepted``?

If I'm misunderstanding let me know. I don't want to slow down acceptance if I'm not following.

@kwoodson kwoodson Aug 22, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ashcrow, I'll try and explain. I'm not in love with this method of approving but I'm not sure how else to accomplish this task.

The node first comes up with a kubeconfig placed on the host through cloud user_data. The host uses the kubeconfig (token) to talk to the master API/controllers.

  1. This first node request is from the service account to talk to the API from the node. Inside of the csr (oc get csr) on the master it returns a field named "username". This "username" field has the service account in it. The admin calls oc adm certificate approve/deny <csr> and the certificate is approved or denied.
  2. Once the service account is approved to talk to the API/controllers, a joining request is issued to the node. The second csr that comes into the master is for the node itself to join the cluster. The "username" field has the name of the node in it. Thus, line 128 must match the username in order for us to consider the node accepted only after both 1 and 2 have been approved.

Its kind of confusing that there are 2 csr's per node. Only after the 2nd one is approved do we consider the node node['accepted']=True and only the second csr has the node's name in the username field.

Hopefully this sheds some light on it. If not, we can walk through it tomorrow and I can demonstrate it better.

If we deny the 1st request then it will never issue the 2nd. I can't think of a scenario where you would allow the server API access but then deny the node into the cluster. It would probably be a security issue if this were to happen. Once denied I was unable to then re-approve the node. It never exited the denied state.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The way you describe the flow makes sense. It's not that unlike Commissaire's flow but using certificates instead of using key generation. I guess I'm just having a hard time following it in the code. The way I read the code is that no matter if the node is marked denied or accepted it will be accepted as accepted is hardcoded in the call. However, based on your testing and explanation, it sounds like I'm incorrect and it's just a complicated code path.

@ashcrow

ashcrow commented Aug 21, 2017

Copy link
Copy Markdown
Member
************* Module oc_adm_csr

roles/lib_openshift/library/oc_adm_csr.py:1493: [W0311(bad-indentation), ] Bad indentation. Found 24 spaces, expected 20

error: lint error 4.

@kwoodson

Copy link
Copy Markdown
Contributor Author

aos-ci-test

@openshift-bot

Copy link
Copy Markdown

success: "aos-ci-jenkins/OS_3.6_NOT_containerized, aos-ci-jenkins/OS_3.6_NOT_containerized_e2e_tests" for ca0dc1c (logs)

@openshift-bot

Copy link
Copy Markdown

success: "aos-ci-jenkins/OS_3.6_containerized, aos-ci-jenkins/OS_3.6_containerized_e2e_tests" for ca0dc1c (logs)

@ashcrow ashcrow left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As noted it's a little hard to follow some of the logic. The logic has been tested by Kenny (whom I trust) and it's probably a good idea to get it out there so people can play with it and report any issues they may find.

timeout=timeout)

return {'failed': True,
'msg': 'Unknown state passed. %s' % state}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't forget to move to format over time!

@ashcrow

ashcrow commented Aug 22, 2017

Copy link
Copy Markdown
Member

@sdodson @kwoodson I'm keen on merging this. Any objections?

@kwoodson

Copy link
Copy Markdown
Contributor Author

@ashcrow, since there exists only a single code path currently calling this, I think the impact is very low that it affects anything else.

@sdodson
sdodson requested a review from ashcrow August 22, 2017 13:30
@sdodson

sdodson commented Aug 22, 2017

Copy link
Copy Markdown
Member

@sdodson @kwoodson I'm keen on merging this. Any objections?

I haven't had a chance to look, but I trust you two to decide when it's ready.

@ashcrow

ashcrow commented Aug 22, 2017

Copy link
Copy Markdown
Member

[merge]

@openshift-bot

openshift-bot commented Aug 22, 2017 •

Copy link
Copy Markdown

continuous-integration/openshift-jenkins/merge Waiting: You are in the build queue at position: 3

@openshift-bot

Copy link
Copy Markdown

Evaluated for openshift ansible merge up to ca0dc1c

@openshift-bot

Copy link
Copy Markdown

[test]ing while waiting on the merge queue

@openshift-bot

Copy link
Copy Markdown

Evaluated for openshift ansible test up to ca0dc1c

@openshift-bot

Copy link
Copy Markdown

continuous-integration/openshift-jenkins/test FAILURE (https://ci.openshift.redhat.com/jenkins/job/test_pull_request_openshift_ansible/489/) (Base Commit: b107f67) (PR Branch Commit: ca0dc1c)

@ashcrow

ashcrow commented Aug 22, 2017

Copy link
Copy Markdown
Member
    Test Panicked
    runtime error: index out of range
    /usr/local/go/src/runtime/panic.go:489

    Full Stack Trace
    	/usr/local/go/src/runtime/panic.go:489 +0x2cf
    github.com/openshift/origin/test/extended/router.glob..func2.1()
    	/go/src/github.com/openshift/origin/test/extended/router/metrics.go:62 +0x6ae
    github.com/openshift/origin/vendor/github.com/onsi/ginkgo/internal/leafnodes.(*runner).runSync(0xc4213170e0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
    	/go/src/github.com/openshift/origin/test/extended/util/test.go:120 +0x3d4
    github.com/openshift/origin/test/extended.TestExtended(0xc42089bba0)
    	/go/src/github.com/openshift/origin/_output/local/go/src/github.com/openshift/origin/test/extended/extended_test.go:35 +0x40
    testing.tRunner(0xc42089bba0, 0x36198b8)
    	/usr/local/go/src/testing/testing.go:657 +0x96
    created by testing.(*T).Run
    	/usr/local/go/src/testing/testing.go:697 +0x2ca

@ashcrow

ashcrow commented Aug 22, 2017

Copy link
Copy Markdown
Member

[merge]

@kwoodson

Copy link
Copy Markdown
Contributor Author

flake openshift/origin#13975

@kwoodson

Copy link
Copy Markdown
Contributor Author

[merge]

@sdodson
sdodson merged commit 66f5e69 into openshift:master Aug 23, 2017
@sdodson

sdodson commented Aug 23, 2017

Copy link
Copy Markdown
Member

The only failure in the last test was a known flake. merging.

@kwoodson
kwoodson deleted the oc_adm_csr branch September 18, 2017 14:28
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.

4 participants