@oxy.so/app-preset 6.3.0 → 6.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -82,10 +82,8 @@ plugins: [
82
82
 
83
83
  This adds the iOS `keychain-access-groups` entitlement
84
84
  (`$(AppIdentifierPrefix)group.so.oxy.shared`; only Commons and the Peable wallet get
85
- more, their `.dev` builds the `.dev` groups, and any other app naming `so.oxy.identity` or
86
- `so.oxy.wallet` in any spelling fails prebuild — ADR 0062 of the oxy repo;
87
- `oxy-check-keychain-entitlements <bundle-id> ios` runs the same policy over what prebuild
88
- wrote), the Oxy `expo-build-properties`
85
+ more, their `.dev` builds the `.dev` groups — ADR 0062 of the oxy repo, see
86
+ [Keychain access groups](#keychain-access-groups)), the Oxy `expo-build-properties`
89
87
  defaults (iOS `deploymentTarget 16.4`; Android ProGuard + resource shrinking — the
90
88
  Android compile/target SDK and build tools are the Expo SDK's own, never pinned here), and `@oxy.so/services/plugins/withOxySharedPermissions`:
91
89
  the app declares and requests the signature-level `so.oxy.permission.IDENTITY` and
@@ -104,6 +102,30 @@ The iOS and build-property pieces are overridable:
104
102
  }]
105
103
  ```
106
104
 
105
+ ##### Keychain access groups
106
+
107
+ Since 6.4.0 an app's `keychain-access-groups` must be EXACTLY its bundle id's list, in
108
+ order (the first entry is the default group, which decides the app's role):
109
+
110
+ | Bundle id | Groups (each `$(AppIdentifierPrefix)<group>`) |
111
+ |---|---|
112
+ | `so.oxy.commons` | `so.oxy.identity`, `so.oxy.wallet`, `group.so.oxy.shared` |
113
+ | `so.oxy.commons.dev` | `so.oxy.identity.dev`, `so.oxy.wallet.dev`, `group.so.oxy.shared` |
114
+ | `to.peable.app` | `so.oxy.wallet`, `group.so.oxy.shared` |
115
+ | `to.peable.app.dev` | `so.oxy.wallet.dev`, `group.so.oxy.shared` |
116
+ | every other app | `group.so.oxy.shared` |
117
+
118
+ optionally followed by the app's own `$(AppIdentifierPrefix)<its bundle id>` (a holder may
119
+ also still list the shared group alone, before its split build). Anything else fails
120
+ prebuild, in particular another app's bundle id: `<TEAM>.<bundle id>` is that app's private
121
+ group, where its session lives. Each entry is spelled exactly `$(AppIdentifierPrefix)<group>`.
122
+ The check runs at prebuild (`withOxyKeychain`, and `withOxyKeychainPolicy` through
123
+ `withOxyUpdates` for apps that declare `ios.entitlements` themselves), and
124
+ `oxy-check-keychain-entitlements <bundle-id> <ios-dir-or-file> [--team-id <TEAMID>]` runs it
125
+ over what a prebuild or a codesign wrote: Oxy's shared native release workflow runs it on
126
+ every release, which therefore needs this package at 6.4.0 or later.
127
+ See `docs/identity/ios-keychain-access-groups.md` in the oxy repo.
128
+
107
129
  ##### Dropping React Native's GIF / WebP decoders (opt-in, Expo SDK 58+)
108
130
 
109
131
  An app that renders no GIF and no animated WebP through react-native's own
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxy.so/app-preset",
3
- "version": "6.3.0",
3
+ "version": "6.4.0",
4
4
  "description": "The Oxy distro of Expo — centralized Expo config plugin, Metro/Babel/ESLint factories, Tailwind base CSS and TypeScript bases shared by every Oxy app (Mention, Homiio, Allo, accounts, …). A zero-build package: apps replace copy-pasted config with a single dependency bump.",
5
5
  "main": "./app.plugin.js",
6
6
  "publishConfig": {
@@ -21,18 +21,35 @@
21
21
  * JavaScript from a dev server, so they never get the production restricted
22
22
  * groups: they hold the `.dev` ones, and a production id may not name those.
23
23
  *
24
- * Every entry is NORMALISED before it is judged (`normalizeGroupName`): leading
25
- * build variables (`$(AppIdentifierPrefix)`, `$(TeamIdentifierPrefix)`,
26
- * `${…}`, nested), a leading ten-character team id and surrounding whitespace
27
- * are stripped, and the name is compared without case. An entry that names a
28
- * restricted group must then be spelled EXACTLY `$(AppIdentifierPrefix)<group>`
29
- * (or `<TEAMID>.<group>` when checking built entitlements for that team), and
30
- * an entry still carrying a build variable or a wildcard after normalisation
31
- * cannot be judged and is refused.
24
+ * Every entry is spelled EXACTLY `$(AppIdentifierPrefix)<group>` (or
25
+ * `<TEAMID>.<group>` when checking built entitlements for that team). Any other
26
+ * entry is NORMALISED (`normalizeGroupName`: leading build variables such as
27
+ * `$(TeamIdentifierPrefix)` or `${…}`, nested, a leading ten-character team id
28
+ * and surrounding whitespace are stripped, case is ignored) only to say why it
29
+ * is refused: another spelling of an allowed group, a restricted group this
30
+ * app does not hold, or a group that is not this app's at all. An entry still
31
+ * carrying a build variable or a wildcard after normalisation cannot be judged.
32
32
  *
33
- * Every other app keeps the shared group only. An app config that names a
34
- * restricted group without being its holder fails prebuild; the entitlement is
35
- * native, so this is the one place it can be stopped before it ships.
33
+ * The list is EXACT, not a floor (R5-4). An app may list:
34
+ *
35
+ * | Bundle id | `keychain-access-groups` |
36
+ * |---------------------------------|--------------------------------------------------|
37
+ * | `so.oxy.commons` | `[identity, wallet, shared]` |
38
+ * | `so.oxy.commons.dev` | `[identity.dev, wallet.dev, shared]` |
39
+ * | `to.peable.app` | `[wallet, shared]` |
40
+ * | `to.peable.app.dev` | `[wallet.dev, shared]` |
41
+ * | every other app | `[shared]` |
42
+ *
43
+ * each optionally followed by the app's OWN application group,
44
+ * `$(AppIdentifierPrefix)<its own bundle id>`, which Apple grants it anyway.
45
+ * A holder may also still list `[shared]` alone: the build before its split,
46
+ * which reads nothing secret. Nothing else, in particular no other bundle id:
47
+ * `<TEAM>.<bundle id>` is each app's private group (ADR 0062 D6, its session
48
+ * and its own items live there), and every app of the team may list any of the
49
+ * team's groups, so an app naming another app's id reads that app's items.
50
+ * The entitlement is native, so prebuild is the one place it can be stopped
51
+ * before it ships; `oxy-check-keychain-entitlements` checks what a prebuild or
52
+ * a codesign wrote, in CI and in every release build.
36
53
  */
37
54
  const PREFIX = '$(AppIdentifierPrefix)';
38
55
 
@@ -127,19 +144,44 @@ function refuse(message) {
127
144
  throw new Error(`[@oxy.so/app-preset] ${message} (docs/identity/ios-keychain-access-groups.md)`);
128
145
  }
129
146
 
147
+ /** The spelling an allowed group must have: `$(AppIdentifierPrefix)<name>`, or `<teamId>.<name>`. */
148
+ function pinnedEntry(name, teamId) {
149
+ return teamId === undefined ? `${PREFIX}${name}` : `${teamId}.${name}`;
150
+ }
151
+
152
+ /**
153
+ * The lists this bundle id may ship, without its optional trailing own group:
154
+ * its holder layout (or the shared group alone, before its split build), or
155
+ * the shared group for every other app. An empty list is allowed too: it names
156
+ * no group, like an app without the entitlement.
157
+ * @param {string|undefined} bundleId
158
+ * @returns {readonly (readonly string[])[]}
159
+ */
160
+ function allowedKeychainLayouts(bundleId) {
161
+ const layouts = [[], [G.shared]];
162
+ if (Object.hasOwn(HOLDER_LAYOUTS, bundleId ?? '')) layouts.push(HOLDER_LAYOUTS[bundleId]);
163
+ return layouts;
164
+ }
165
+
130
166
  /**
131
167
  * Throw unless `entries` (a `keychain-access-groups` value) is one this bundle
132
- * id may ship: every entry judgeable, a restricted group only for its holders
133
- * and only in its one spelling, and a holder's layout as the leading entries,
134
- * in order.
168
+ * id may ship: every entry judgeable and in its one spelling, each one of the
169
+ * Oxy groups this bundle id holds or its own application group, and the whole
170
+ * list exactly its layout (`allowedKeychainLayouts`), in order, optionally
171
+ * followed by its own application group.
135
172
  *
136
173
  * @param {string|undefined} bundleId
137
174
  * @param {unknown} entries
138
175
  * @param {{ teamId?: string }} [options] `teamId`: the entries are BUILT
139
- * (codesigned) entitlements of that team, so a restricted group is spelled
176
+ * (codesigned) entitlements of that team, so a group is spelled
140
177
  * `<teamId>.<group>` instead of `$(AppIdentifierPrefix)<group>`.
141
178
  */
142
179
  function assertOxyKeychainGroups(bundleId, entries, options = {}) {
180
+ // An app's implicit own group must never alias a restricted shared group,
181
+ // even when its entitlements omit keychain-access-groups altogether.
182
+ if (typeof bundleId === 'string' && restrictedGroup(bundleId) !== undefined) {
183
+ refuse(`${bundleId} is reserved for an Oxy restricted keychain group, not an app bundle id`);
184
+ }
143
185
  if (entries === undefined || entries === null) return;
144
186
  const app = bundleId ?? 'This app';
145
187
  if (!Array.isArray(entries)) {
@@ -149,12 +191,24 @@ function assertOxyKeychainGroups(bundleId, entries, options = {}) {
149
191
  if (teamId !== undefined && !TEAM_ID.test(teamId)) {
150
192
  refuse(`"${teamId}" is not an Apple team id (ten upper-case letters and digits)`);
151
193
  }
152
- const layout = Object.hasOwn(HOLDER_LAYOUTS, bundleId ?? '') ? HOLDER_LAYOUTS[bundleId] : [];
194
+ const layout = keychainGroupsFor(bundleId);
195
+ // The groups this app may name: its layout's, and its own application group.
196
+ const own = typeof bundleId === 'string' && bundleId !== '' ? bundleId : undefined;
197
+ const allowed = own === undefined ? [...layout] : [...layout, own];
198
+ const allowedByName = new Map(allowed.map((name) => [name.toLowerCase(), name]));
199
+ const ownHint =
200
+ own === undefined ? '' : ` and, after them, its own application group "${PREFIX}${own}"`;
153
201
 
154
- const names = entries.map((entry) => {
202
+ /** The allowed group `entry` names, in its one spelling; throws for anything else. */
203
+ const judge = (entry) => {
155
204
  if (typeof entry !== 'string') {
156
205
  refuse(`${app}: every keychain-access-groups entry must be a string`);
157
206
  }
207
+ // The exact spelling first: a bundle id whose first label is ten
208
+ // characters would otherwise be read as a team prefix below.
209
+ const exact = allowed.find((name) => entry === pinnedEntry(name, teamId));
210
+ if (exact !== undefined) return exact;
211
+
158
212
  const name = normalizeGroupName(entry);
159
213
  if (name === '' || /[$*?\s]/.test(name)) {
160
214
  refuse(
@@ -162,9 +216,14 @@ function assertOxyKeychainGroups(bundleId, entries, options = {}) {
162
216
  'whitespace past its team prefix). Name the group literally after $(AppIdentifierPrefix).',
163
217
  );
164
218
  }
219
+ const canonical = allowedByName.get(name.toLowerCase());
220
+ if (canonical !== undefined) {
221
+ refuse(
222
+ `${app} must spell the keychain access group "${entry}" exactly "${pinnedEntry(canonical, teamId)}"`,
223
+ );
224
+ }
165
225
  const restricted = restrictedGroup(name);
166
- if (restricted === undefined) return name;
167
- if (!layout.includes(restricted)) {
226
+ if (restricted !== undefined) {
168
227
  refuse(
169
228
  `${app} may not list the keychain access group "${entry}" (${restricted}): only Commons holds ` +
170
229
  'the identity group and only Commons and the Peable wallet the wallet group, the production ' +
@@ -172,28 +231,34 @@ function assertOxyKeychainGroups(bundleId, entries, options = {}) {
172
231
  'group.so.oxy.shared',
173
232
  );
174
233
  }
175
- const pinned = teamId === undefined ? `${PREFIX}${restricted}` : `${teamId}.${restricted}`;
176
- if (entry !== pinned) {
177
- refuse(`${app} must spell the keychain access group "${entry}" exactly "${pinned}"`);
178
- }
179
- return restricted;
180
- });
234
+ refuse(
235
+ `${app} may not list the keychain access group "${entry}": it is not one of this app's groups ` +
236
+ `[${layout.join(', ')}]${ownHint}. "<TEAM>.<bundle id>" is that app's own private group ` +
237
+ "(ADR 0062 D6), so naming another app's bundle id, or any other group, lets this app read " +
238
+ 'items that are not its own',
239
+ );
240
+ };
241
+ const names = [];
242
+ for (const entry of entries) names.push(judge(entry));
181
243
 
182
- if (layout.length > 0 && names.some((name) => restrictedGroup(name) !== undefined)) {
183
- const leading = names.slice(0, layout.length);
184
- if (leading.join(',') !== layout.join(',')) {
185
- refuse(
186
- `${bundleId} must list its keychain access groups as [${layout.join(', ')}] first, in that ` +
187
- `order (got [${names.join(', ')}]): the first entry is the default group, which decides ` +
188
- 'where the identity is written and what @oxy.so/core lets this app read',
189
- );
190
- }
244
+ const base = own !== undefined && names.at(-1) === own ? names.slice(0, -1) : names;
245
+ const fits = allowedKeychainLayouts(bundleId).some(
246
+ (candidate) => candidate.join(',') === base.join(','),
247
+ );
248
+ if (!fits) {
249
+ refuse(
250
+ `${app} must list its keychain access groups as exactly [${layout.join(', ')}], in that order` +
251
+ `${own === undefined ? '' : `, optionally followed by its own application group ${PREFIX}${own}`}` +
252
+ ` (got [${names.join(', ')}]): the first entry is the default group, which decides where the ` +
253
+ 'identity is written and what @oxy.so/core lets this app read',
254
+ );
191
255
  }
192
256
  }
193
257
 
194
258
  module.exports = {
195
259
  OXY_KEYCHAIN_GROUPS,
196
260
  HOLDER_LAYOUTS,
261
+ allowedKeychainLayouts,
197
262
  assertOxyKeychainGroups,
198
263
  keychainEntries,
199
264
  keychainGroupsFor,
@@ -14,8 +14,12 @@
14
14
  *
15
15
  * The Oxy groups are put FIRST, in their order; entries the app or another
16
16
  * plugin already declared are kept after them. Then the policy is checked on
17
- * the result, and on the app's own `ios.entitlements`: an app that is not a
18
- * holder and names the identity or wallet group fails prebuild.
17
+ * the result, and on the app's own `ios.entitlements`: the list must be
18
+ * EXACTLY the bundle id's layout, optionally followed by the app's own
19
+ * `$(AppIdentifierPrefix)<bundle id>`. An app that is not a holder and names
20
+ * the identity or wallet group, or any app naming another group (another app's
21
+ * bundle id above all: that is the other app's private group, ADR 0062 D6),
22
+ * fails prebuild.
19
23
  *
20
24
  * @param {import('expo/config').ExpoConfig} config
21
25
  * @param {string|string[]} [keychainGroups] Group name(s) without the prefix.