Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Enable cert updates #50

Merged
merged 1 commit into from
May 5, 2015
Merged

Enable cert updates #50

merged 1 commit into from
May 5, 2015

Conversation

sevenmachines
Copy link
Contributor

When we change the certificate in our cloud formation config we want a way to update the certificates on instances, and to set these certificates on any https load balancers on the stack.
This patch creates a fab_task update_certs() to carry out both of these tasks, first removing/adding the certificates using IAM, then using a simple ELB class to set_ssl_certificates() on any https listeners on the stacks load_balancers

# necessarily a problem
logging.info("ELB::set_ssl_certificates: "
"No load balancers found in stack, "
"no certificate updates needed")
Copy link
Contributor

Choose a reason for hiding this comment

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

This probably be a warning or an error - the user has requested something to be updated that couldn't be. This also means we should likely return a non-0 exit code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was going to throw an exception here to allow the caller to deal with there being no elbs or ignoring, exiting seems a little strict?

@ashb
Copy link
Contributor

ashb commented Mar 25, 2015

Can you also rebase this into a small number of commits? In this case probably just 1.

@sevenmachines sevenmachines self-assigned this Apr 8, 2015
@sevenmachines sevenmachines force-pushed the enable_cert_updates branch 2 times, most recently from 5eab969 to 1ee7124 Compare April 8, 2015 14:33
@ashb
Copy link
Contributor

ashb commented Apr 8, 2015

@niallcreech Travis is reporting that the tests are failing

FAIL: test_ssl_delete (tests.test.CfnTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/ministryofjustice/bootstrap-cfn/tests/test.py", line 246, in test_ssl_delete
    self.assertTrue(x)
AssertionError: False is not true

Did you change the API here perhaps?

@sevenmachines
Copy link
Contributor Author

Yep, I'm on it. its not the API, delete checks to see if the cert exists. I'm setting up the test to mock the call to list_server_certs.

@sevenmachines sevenmachines changed the title Enable cert updates Enable cert updates (WIP) Apr 8, 2015
@coveralls
Copy link

Coverage Status

Coverage decreased (-3.3%) to 46.13% when pulling a15ee7f on enable_cert_updates into e4e41a2 on master.

@sevenmachines
Copy link
Contributor Author

  • Update test_ssl_delete test case to reflect new 'check cert exists' flow for IAM class

Now expanding tests to cover update_certs fab_task

@sevenmachines sevenmachines force-pushed the enable_cert_updates branch 3 times, most recently from 3f096af to 9e63a10 Compare April 9, 2015 15:39
@sevenmachines
Copy link
Contributor Author

Need to fill out the test cases then hopefully done

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.68%) to 50.58% when pulling d604429 on enable_cert_updates into 78707b7 on master.

@sevenmachines sevenmachines changed the title Enable cert updates (WIP) Enable cert updates Apr 10, 2015
@sevenmachines
Copy link
Contributor Author

Added more test cases, hopefully ready for review

@sevenmachines sevenmachines removed their assignment Apr 10, 2015
@sevenmachines sevenmachines added ready and removed ready labels Apr 10, 2015
Also handle settings the certificates on ELB's
"""
if verbose:
logging.basicConfig(level=logging.INFO)
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than setting a flag called verbose here, it would be better to just use the logger with different levels. Like logging.info when you want it to appear for everyone and logging.debug when you want it only if the verbosity is increased. Then we can set the level globally in the fabfile maybe?

@sevenmachines
Copy link
Contributor Author

  • Dropped verbose arg from fab task
  • elb: Made load_balance search more pythonistic
  • iam: Made exception catching more specific to KeyError
  • iam: Move to pythonic mid-method returns rather than collecting
    results and returning on method exit
  • iam: Combine cert_exists and force checks on if
  • iam: combine some dictionary calls to compact code
  • iam: Fix remote and local cert data comparison
  • iam: Compact update_ssl_certificates checks on force and exists

@sevenmachines
Copy link
Contributor Author

Not sure about some of this 'forcing' logic

load_balancer_resources = self.cfn.get_stack_load_balancers(stack_name)
found_load_balancer_names = [lb.physical_resource_id for lb in load_balancer_resources]
# Use load balancer names to filter gettingload balancer details
if len(found_load_balancer_names) > 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

think we might want load_balancers=[] here or in the else block because if this is not true the next if statement will fail (if I'm reading it right).

@mattmb
Copy link
Contributor

mattmb commented Apr 20, 2015

@niallcreech and I have just had a good chat about this.

Two things we thought of:

  • Force may not be necessary. Use cases are my repo has the correct cert, I run the tool, nothing changes. My repo has a new cert, I run the tool, the cert gets updated.
  • Multiple ELBs with different certs. We think it's probably safe the way it works at the moment because the cert wont be updated, the ARN wont change etc. But might be nicer to track what's changing (rather than an updated count (maybe a dictionary of what's updated)

@stuartornum
Copy link
Contributor

This is a massive PR, I have no idea where to start

@sevenmachines
Copy link
Contributor Author

Mostly covered with Matt yesterday, I’ve got a couple of small changes to make but unfortunately I’ve no internet until the afternoon. Press on with any bootstrap work you’re doing, I’ll fix this up around it once you’re finished

@sevenmachines
Copy link
Contributor Author

  • Reworked IAM force options to remove them and have sane logic
  • Return list of updated elb's when we run update_ssl's
  • Updated tests to reflect new force and list return logic

@sevenmachines
Copy link
Contributor Author

Will need to wait until trim_the_fat has been merged and see how rebasey this will be before moving to review

@mattmb
Copy link
Contributor

mattmb commented Apr 21, 2015

Cool, thanks @niallcreech I've got my fingers crossed with the git gods that it won't be too conflicty 😄

    Created a fab task to update certificates on a stack. Checks are carried out to see if the current local and remote certificates are the same,
    if not the certificates are uploaded and and load balancers with certificates in the stack will be updated
    fab_tasks:
        - Create a fab task update_certs to update the ssl certificates from the config
        - Small delay between updating certificates on instances and load balancer to avoid setting the load balancer cert when ARN is available but the
            certificate is not properly registered
    iam:
        - Added getting an arn from a certificate name to the IAM class.
        - Simplify getting an arn for certs using boto get_server_certificate
        - Handle exceptions when trying to delete/upload a certificate
        - Simplify upload ssl logic to error on trying to update a missing
            certificate
    elb:
        - Create an ELB class to handle interaction with the stacks load balancers.
        - Throw an exception if we try to set certs on elbs when none are defined in the config
    cloudformation:
        - Added utility method to get a list of load balancers for the stack
    test_iam:
        - Added test cases to cover noew iam things
@mattmb
Copy link
Contributor

mattmb commented May 1, 2015

I'd say this looks good now. Anyone else want to comment before I merge?

@sevenmachines sevenmachines removed their assignment May 2, 2015
stuartornum added a commit that referenced this pull request May 5, 2015
@stuartornum stuartornum merged commit 7cfdad7 into master May 5, 2015
@stuartornum stuartornum deleted the enable_cert_updates branch May 5, 2015 11:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants