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

[match][sigh] add option to automatically renew expired certificates (defaults to enabled) #21691

Merged
merged 9 commits into from Jan 15, 2024

Conversation

nekrich
Copy link
Contributor

@nekrich nekrich commented Dec 4, 2023

Checklist

  • I've run bundle exec rspec from the root directory to see all new and existing tests pass
  • I've followed the fastlane code style and run bundle exec rubocop -a to ensure the code style is valid
  • I see several green ci/circleci builds in the "All checks have passed" section of my PR (connect CircleCI to GitHub if not)
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary.
  • I've added or updated relevant unit tests.

Motivation and Context

Motivation: Automation 😅, and we had one of our certs expired.

Current flow on expired certificate:

  1. Nuke or remove certs and provisioning profiles manually from the storage. Which is scary.
  2. Remove all provisioning profiles from the portal.

New flow: do nothing, match/sync_code_signing will do all the things for you 🎉.

Description

Check the certificate expiration date for renewable certificates. Remove expired certs from storage.
This behavior is optional, and there is a new parameter renew_expired_certs to turn it on.

Extra profile validation

Provisioning profiles are not invalidated automatically on the dev portal when the certificate expires. They become Invalid only when opened directly in the portal 🤷. We need to do an extra check on the expiration date to ensure the profile is valid.

Git commit of removed files

Commit deletion of only listed deleted files. Encryption modifies all files in git.

Profile installation

I moved the profile installation logic a little bit lower. Now, only valid profiles are installed 🧹.

The working_directory parameter was not used in the fetch_certificate, so I removed it.

Testing Steps

Tests provided: run match with an expired certificate and active provisioning profiles.

@nekrich nekrich force-pushed the feat/match-renew-expired-cert branch from 0388ecb to e4fc47e Compare December 4, 2023 14:33
@nekrich nekrich changed the title [match]: renew expired certificates [match] renew expired certificates Dec 4, 2023
@nekrich nekrich changed the title [match] renew expired certificates [match] add option to automatically renew expired certificates Dec 4, 2023
Copy link
Collaborator

@lacostej lacostej left a comment

Choose a reason for hiding this comment

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

that's a nice feature. Seems to fix a few corner cases issues as well.

match/lib/match/runner.rb Show resolved Hide resolved
match/lib/match/runner.rb Outdated Show resolved Hide resolved
end
end
ensure # Always clear working_directory after save
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@@ -484,7 +484,14 @@ def certificate_valid?
# @return (Bool) Is the current provisioning profile valid?
# To also verify the certificate call certificate_valid?
def valid?
return status == 'Active'
# Provisioning profiles are not invalidated automatically on the dev portal when the certificate expires.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this mean that this PR also fixes the fact that we were not detecting expired certificates properly before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes 😅. I don't know why Apple does not revoke profiles or make them invalid.
But even in this case, we cannot sign an app since the certificate has expired.

The date is Dec 4, and the expiration date is Dec 1.
The only Expired cert is that I opened it to see why it's not expired, and it expired immediately after opening it.
image

Copy link
Member

Choose a reason for hiding this comment

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

They didn't bother setting up like a cron job that goes and expire everything like once a day 😂

@@ -277,6 +311,10 @@ def fetch_provisioning_profile(params: nil, certificate_id: nil, app_identifier:
return nil
end

if Helper.mac?
Copy link
Collaborator

Choose a reason for hiding this comment

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

does the fact that we move this after the previous block means that we stop installing expired profiles into the keychain?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I see no point in installing an expired profile, generating a new one, and installing a new one after.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

match/lib/match/options.rb Outdated Show resolved Hide resolved
match/spec/runner_spec.rb Show resolved Hide resolved
match/lib/match/runner.rb Show resolved Hide resolved
match/lib/match/storage/interface.rb Show resolved Hide resolved
match/lib/match/storage/git_storage.rb Outdated Show resolved Hide resolved
@nekrich nekrich requested a review from lacostej December 8, 2023 13:39
@@ -133,13 +136,48 @@ def update_optional_values_depending_on_storage_type(params)
end
end

def fetch_certificate(params: nil, working_directory: nil, specific_cert_type: nil)
RENEWABLE_CERT_TYPES = [:mac_installer_distribution, :development, :distribution, :enterprise]
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe we should rename this to RENEWABLE_CERT_TYPES_VIA_API?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's for sure will improve readability. Done in eb0db7b.

@nekrich
Copy link
Contributor Author

nekrich commented Dec 14, 2023

Rebased, fixed conflicts and updated the test to include new parameters for the certificates_exists stub.

@nekrich nekrich force-pushed the feat/match-renew-expired-cert branch from 3b859ad to 3d8a2d8 Compare December 14, 2023 14:21
Copy link
Member

@rogerluan rogerluan left a comment

Choose a reason for hiding this comment

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

This is a great DX improvement over what we have currently 🎉 thanks for the hard work on this PR @nekrich ! 🙌

Just left some suggestions and comments, nothing blocking 😊

match/lib/match/options.rb Outdated Show resolved Hide resolved
match/lib/match/options.rb Outdated Show resolved Hide resolved
match/spec/spec_helper.rb Outdated Show resolved Hide resolved
match/spec/spec_helper.rb Show resolved Hide resolved
@@ -484,7 +484,14 @@ def certificate_valid?
# @return (Bool) Is the current provisioning profile valid?
# To also verify the certificate call certificate_valid?
def valid?
return status == 'Active'
# Provisioning profiles are not invalidated automatically on the dev portal when the certificate expires.
Copy link
Member

Choose a reason for hiding this comment

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

They didn't bother setting up like a cron job that goes and expire everything like once a day 😂

@rogerluan
Copy link
Member

It seems this PR developed conflicts @nekrich, if you could resolve those and my comments above, this PR should be good to go then 💪

@nekrich nekrich force-pushed the feat/match-renew-expired-cert branch from 3d8a2d8 to 37bc483 Compare January 15, 2024 10:16
Co-authored-by: Roger Oba <rogerluan.oba@gmail.com>
@rogerluan
Copy link
Member

Thanks for addressing those changes @nekrich 🙏 I see CI is failing now, could you take a look? 🙇

@nekrich
Copy link
Contributor Author

nekrich commented Jan 15, 2024

Yeah, I'm looking into it. It looks like default renew certs affect all the tests.

Copy link
Member

@rogerluan rogerluan left a comment

Choose a reason for hiding this comment

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

LGTM 💪 Thanks @nekrich ! 🚀

@lacostej any final thoughts on the recent changes before we merge this in?

@lacostej
Copy link
Collaborator

LGTM

@rogerluan rogerluan changed the title [match] add option to automatically renew expired certificates [match][sigh] add option to automatically renew expired certificates (defaults to enabled) Jan 15, 2024
@rogerluan rogerluan merged commit d4c0ca4 into fastlane:master Jan 15, 2024
3 checks passed
rogerluan pushed a commit that referenced this pull request Feb 10, 2024
…21691 and revert the default behavior while we address issues with it (#21812)

* [match] remove the renew_expired_certs option and make behaviour default

* chore: don’t auto renew cert

* chore: remove auto renewal test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants