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

[resign] fix entitlements merging when changing team while resigning #18713

Merged
merged 4 commits into from
May 19, 2021

Conversation

silvervest
Copy link
Contributor

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've read the Contribution Guidelines
  • I've updated the documentation if necessary.

Motivation and Context

These are the changes from #12131 updated to master and with merge conflicts resolved. Please see that issue for more in-depth detail.

This was resubmitted again due to lose head repository branch, but is the same changes.

Description

Testing Steps

supersedes #12131 and #15388

@google-cla
Copy link

google-cla bot commented May 19, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@silvervest
Copy link
Contributor Author

The contents of this PR were approved, and all author CLAs have been signed a couple of times now in the other linked PRs.
@joshdholtz Is there anything (other than time and my messing up the previous PR) blocking this from being approved and merged? Please and thank you!

@joshdholtz joshdholtz changed the title Fix entitlements merging [resign] fix entitlements merging when changing team while resigning May 19, 2021
Copy link
Member

@joshdholtz joshdholtz left a comment

Choose a reason for hiding this comment

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

@silvervest Hello! Do you mind appending the changelog to the top of the file with a summary of the changes here? 😊 After that we can get this merged 💪

@google-cla
Copy link

google-cla bot commented May 19, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@silvervest
Copy link
Contributor Author

Done and done @joshdholtz, cheers!

@joshdholtz
Copy link
Member

@silvervest Thank you! Will smash the merge button when tests are done running 💪

Copy link
Member

@joshdholtz joshdholtz left a comment

Choose a reason for hiding this comment

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

This looks good to me! Thank you so much for reviving this PR (again (again)) ❤️ Really appreciate it!

@silvervest
Copy link
Contributor Author

Great! And just for the official merge record, want to provide thanks to @kapfab for actually authoring this change in the first place 🥂

@kapfab
Copy link
Contributor

kapfab commented May 19, 2021

You’re welcome. I just hope this PR will finally find its way to a release.

And in case this is needed, I’ll consent to the CLA.

@kapfab
Copy link
Contributor

kapfab commented May 19, 2021

@googlebot I consent.

@google-cla
Copy link

google-cla bot commented May 19, 2021

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@joshdholtz joshdholtz merged commit abe50be into fastlane:master May 19, 2021
@kapfab
Copy link
Contributor

kapfab commented May 19, 2021

Just had a quick look at the changes.

I think lines 801-808 (replacement of App ID and Team ID) could be removed, as lines 848-858 do the same on the whole entitlements file (which indeed seems a better option as other entitlements values could reference the App ID or Team ID):

if [[ "$ID_TYPE" == "APP_ID" ]]; then
# Replace old value with new value in patched entitlements
log "Replacing old app ID '$OLD_APP_ID' with new app ID '$NEW_APP_ID'"
ENTITLEMENTS_VALUE=$(echo "$ENTITLEMENTS_VALUE" | sed "s/$OLD_APP_ID/$NEW_APP_ID/g")
elif [[ "$ID_TYPE" == "TEAM_ID" ]]; then
# Replace old team identifier with new value
log "Replacing old team ID '$OLD_TEAM_ID' with new team ID '$NEW_TEAM_ID'"
ENTITLEMENTS_VALUE=$(echo "$ENTITLEMENTS_VALUE" | sed "s/$OLD_TEAM_ID/$NEW_TEAM_ID/g")

if [[ "$ID_TYPE" == "APP_ID" ]]; then
# Replace old value with new value in patched entitlements
log "Replacing old app identifier prefix '$OLD_APP_ID' with new value '$NEW_APP_ID'"
/usr/bin/sed -i .bak "s/$OLD_APP_ID/$NEW_APP_ID/g" "$PATCHED_ENTITLEMENTS"
elif [[ "$ID_TYPE" == "TEAM_ID" ]]; then
# Replace old team identifier with new value
log "Replacing old team ID '$OLD_TEAM_ID' with new team ID: '$NEW_TEAM_ID'"
/usr/bin/sed -i .bak "s/$OLD_TEAM_ID/$NEW_TEAM_ID/g" "$PATCHED_ENTITLEMENTS"
else
continue
fi

Also, AFAIR, the tr '\n' '\r’ | … | tr '\r' '\n’ (now removed on line 791) was meant to actually remove the entitlements header (which it does not without it). This does not prevent the whole thing to work as plutil handles that gracefully, but the log will dump the headers for each key.

ENTITLEMENTS_VALUE="$(PlistBuddy -x -c "Print $KEY" "$APP_ENTITLEMENTS" 2>/dev/null | /usr/bin/sed -e 's,.*<plist[^>]*>\(.*\)</plist>,\1,g')"

@kapfab
Copy link
Contributor

kapfab commented May 19, 2021

@silvervest, did you voluntarily rollback you previous commit (dd77fef)?

Also, is there a reason why if [[ "$certificate_name" =~ "Distribution:" ]]; then changed to this?

if [[ "$CERTIFICATE" =~ "Distribution:" ]]; then

I’m a bit worried on this specific change…

@silvervest
Copy link
Contributor Author

silvervest commented May 19, 2021

@silvervest, did you voluntarily rollback you previous commit (dd77fef)?

Hmm! Not voluntarily. I have no idea how that happened, actually.

Also, is there a reason why if [[ "$certificate_name" =~ "Distribution:" ]]; then changed to this?

if [[ "$CERTIFICATE" =~ "Distribution:" ]]; then

That appears to have been a typo from the very first merge conflicts I "fixed" in your original PR. Likely as the change to $certificate_name happened between your original commit and my involvement.
b25f9ce#diff-95cccef747680a2777fd80b592db939260ffbd33ad1e31314635b8b9b01fe933L770-R803

I'll resolve these ASAP and submit another PR. Thanks for catching those @kapfab!

@silvervest
Copy link
Contributor Author

@silvervest, did you voluntarily rollback you previous commit (dd77fef)?

Actually @kapfab I'm looking at this again and I can't see this commit reverted? The file is up to date with this change in master?
https://github.com/fastlane/fastlane/blob/master/sigh/lib/assets/resign.sh#L541

@kapfab
Copy link
Contributor

kapfab commented May 19, 2021

@silvervest, did you voluntarily rollback you previous commit (dd77fef)?

Actually @kapfab I'm looking at this again and I can't see this commit reverted? The file is up to date with this change in master?
https://github.com/fastlane/fastlane/blob/master/sigh/lib/assets/resign.sh#L541

My mistake, I probably saw that on silvervest@caf995e when I was looking for the origin of the certificate-related change.

@silvervest
Copy link
Contributor Author

silvervest commented May 19, 2021

Also, AFAIR, the tr '\n' '\r’ | … | tr '\r' '\n’ (now removed on line 791) was meant to actually remove the entitlements header (which it does not without it). This does not prevent the whole thing to work as plutil handles that gracefully, but the log will dump the headers for each key.

ENTITLEMENTS_VALUE="$(PlistBuddy -x -c "Print $KEY" "$APP_ENTITLEMENTS" 2>/dev/null | /usr/bin/sed -e 's,.*<plist[^>]*>\(.*\)</plist>,\1,g')"

I am really confused by this. I didn't remove this change, and if you look at the .patch of this pull request, that change is definitely in there, but it wasn't part of the merged changes, nor does it show on the files changed tab. I am at a loss...

@kapfab
Copy link
Contributor

kapfab commented May 19, 2021

Also, AFAIR, the tr '\n' '\r’ | … | tr '\r' '\n’ (now removed on line 791) was meant to actually remove the entitlements header (which it does not without it). This does not prevent the whole thing to work as plutil handles that gracefully, but the log will dump the headers for each key.

ENTITLEMENTS_VALUE="$(PlistBuddy -x -c "Print $KEY" "$APP_ENTITLEMENTS" 2>/dev/null | /usr/bin/sed -e 's,.*<plist[^>]*>\(.*\)</plist>,\1,g')"

I am really confused by this. I didn't remove this change, and if you look at the .patch of this pull request, that change is definitely in there, but it wasn't part of the merged changes, nor does it show on the files changed tab. I am at a loss...

It was part of my initial commit that never reached the master branch (until today!), it probably got lost by someone else months ago during one of the different merges that occurred since. Not a big deal, that might be fixed in a future PR.

@fastlane-bot
Copy link

Hey @silvervest 👋

Thank you for your contribution to fastlane and congrats on getting this pull request merged 🎉
The code change now lives in the master branch, however it wasn't released to RubyGems yet.
We usually ship about once a week, and your PR will be included in the next one.

Please let us know if this change requires an immediate release by adding a comment here 👍
We'll notify you once we shipped a new release with your changes 🚀

@fastlane-bot
Copy link

Congratulations! 🎉 This was released as part of fastlane 2.184.0 🚀

@csc-EricWu
Copy link
Contributor

csc-EricWu commented Jun 3, 2021

Hi @silvervest , I updated to the latest Fastlane, but this entitlement is invalid for me. Can you have a look?

com.apple.developer.icloud-container-environment

@csc-EricWu
Copy link
Contributor

WARNING: Changing team while resigning
WARNING: Using these entitlements from the provisioning profile instead of the existing app:
WARNING: App Groups, Merchant IDs (Apple Pay In-App Payments), iCloud Containers, Pass Type IDs (Wallet)
WARNING: If these capabilities are enabled, make sure AppID and provisioning profile are properly configured
WARNING: Resigned app will allow all pass types from the new team, even if old app only allowed a restricted list
sed: 1: "s/<?xml version="1.0" e ...": unterminated substitute pattern
_floatsignTemp/Payload/Fuse.app: replacing existing signature
_floatsignTemp/patchedEntitlements: Could not modify plist, error: Failed to parse value with type -xml

@kapfab
Copy link
Contributor

kapfab commented Jun 3, 2021

Hi @silvervest , I updated to the latest Fastlane, but this entitlement is invalid for me. Can you have a look?

com.apple.developer.icloud-container-environment

Which value did you expect and which one did you get?

@csc-EricWu
Copy link
Contributor

image
This is the bag that was made through Xcode.

image
After Fastlane redesign, it disappeared.

@csc-EricWu
Copy link
Contributor

image
I got an error message

@kapfab
Copy link
Contributor

kapfab commented Jun 3, 2021

After Fastlane redesign, it disappeared.

The only reason I can see for such a behaviour would be that your app did not include this entitlement but your provisioning profile did, which is quite unusual.
Can you unzip your old IPA and run the following command?

codesign -d --verbose --entitlements :- /path/to/unzipped/ipa/Payload/YourAppName.app

@csc-EricWu
Copy link
Contributor

image
Yes, I tried to try again command, no problem.

@csc-EricWu
Copy link
Contributor

csc-EricWu commented Jun 3, 2021

@kapfab

ENTITLEMENTS_VALUE=$(echo "$ENTITLEMENTS_VALUE" | sed "s/$OLD_ICLOUD_ENV/$NEW_ICLOUD_ENV/g")

In this line, I printed it out empty, adjusted the code here locally, and everything was OK

ENTITLEMENTS_VALUE=$NEW_ICLOUD_ENV

@kapfab
Copy link
Contributor

kapfab commented Jun 4, 2021

I still do not understand how you original app ended up in this state.
It would be useful to know if this is an isolated case or if a recent change in Xcode broke the whole thing.

@csc-EricWu
Copy link
Contributor

You need to try it once, I've found the cause of the problem

ENTITLEMENTS_VALUE=$NEW_ICLOUD_ENV

It works for me.

kapfab added a commit to kapfab/fastlane that referenced this pull request Jun 4, 2021
* Fix the way app entitlements are extracted (see fastlane#18713)
* Homogenise sed invocations (following fastlane#17075)
@kapfab
Copy link
Contributor

kapfab commented Jun 4, 2021

After some investigation, your issue is related to the way entitlement values are extracted (what the lost tr '\n' '\r' | … | tr '\r' '\n' discussed above was meant to fix).

Your workaround might work (even though you feed the — quite permissive — plutil with Production instead of the <string>Production</string> XML element it expects), but this issue will affect other future entitlements whose APP_ID/TEAM_ID/ICLOUD_ENV fragment is to be patched.

I will open a new PR with a less specific fix.

Could you try to resign your app with this change (kapfab@8e98846) to confirm this solves your issue?

@csc-EricWu
Copy link
Contributor

After my test, the problem was solved perfectly. And I deliver to Appstore connect. thank you.

gem "fastlane", :git => "https://github.com/kapfab/fastlane", :branch => "resign_app_entitlements_fixes"

joshdholtz pushed a commit that referenced this pull request Jun 5, 2021
* Fix the way app entitlements are extracted (see #18713)
* Homogenise sed invocations (following #17075)
@fastlane fastlane locked and limited conversation to collaborators Aug 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants