-
Notifications
You must be signed in to change notification settings - Fork 48
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
PXP-10541 Client credentials rotation #1068
Conversation
Pull Request Test Coverage Report for Build 13269
💛 - Coveralls |
) | ||
|
||
print(f"Droppping 'unique client name' constraint: '{name_constraints[0]}'") | ||
op.drop_constraint(name_constraints[0], "client") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure that it's entirely reuseable here, but there were some generic functions for adding/removing constraints in the old migration script:
fence/bin/old_migration_script.py
Lines 469 to 509 in 1b52c51
def add_unique_constraint_if_not_exist(table_name, column_name, driver, metadata): | |
table = Table(table_name, metadata, autoload=True, autoload_with=driver.engine) | |
index_name = "{}_{}_key".format(table_name, column_name) | |
if column_name in table.c: | |
indexes = [index.name for index in table.indexes] | |
if index_name not in indexes: | |
with driver.session as session: | |
session.execute( | |
'ALTER TABLE "{}" ADD CONSTRAINT {} UNIQUE ({});'.format( | |
table_name, index_name, column_name | |
) | |
) | |
session.commit() | |
def drop_unique_constraint_if_exist(table_name, column_name, driver, metadata): | |
table = Table(table_name, metadata, autoload=True, autoload_with=driver.engine) | |
constraint_name = "{}_{}_key".format(table_name, column_name) | |
if column_name in table.c: | |
constraints = [ | |
constaint.name for constaint in getattr(table.c, column_name).constraints | |
] | |
unique_index = None | |
for index in table.indexes: | |
if index.name == constraint_name: | |
unique_index = index | |
if constraint_name in constraints or unique_index: | |
with driver.session as session: | |
session.execute( | |
'ALTER TABLE "{}" DROP CONSTRAINT {};'.format( | |
table_name, constraint_name | |
) | |
) | |
session.commit() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed while writing this migration that the name of the index was different in my dev env than locally, so i had to figure out a generic way of finding the name.
These functions would have the same problem since they assume that the index name is "<table_name>_<column_name>_key"
. Maybe it's a cleaner way of querying the indexes though, if that's what you mean, i can change my code to do it the same way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong opinion, if this didn't work out of the box then I think what you have is fine
@@ -34,6 +34,18 @@ def json_res(data): | |||
return flask.Response(json.dumps(data), mimetype="application/json") | |||
|
|||
|
|||
def generate_client_credentials(confidential): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docstring pls
@@ -276,6 +276,41 @@ def split_uris(uris): | |||
logger.info(nothing_to_do_msg) | |||
|
|||
|
|||
def rotate_client_action(DB, client_name, expires_in=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docstring pls
def rotate_client_action(DB, client_name, expires_in=None): | ||
driver = SQLAlchemyDriver(DB) | ||
with driver.session as s: | ||
client = s.query(Client).filter(Client.name == client_name).first() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering if we need to be more particular than .first() (vs getting the one with the latest expiration or something), but since everything is being copied every time to the new client, I think it's fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comments
Jira Ticket: PXP-10541
New Features
fence-create client-rotate
command to receive a new set of credentials for a client without deleting the old credentials first. This allows for a rotation without downtime.Deployment changes