-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathupdateTccDb.ts
More file actions
206 lines (196 loc) · 7.4 KB
/
Copy pathupdateTccDb.ts
File metadata and controls
206 lines (196 loc) · 7.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import { release } from "os";
import { execSync } from "child_process";
import { ERR_MACOS_UNABLE_TO_WRITE_USER_TCC_DB } from "../errors";
const epoch = +Date.now();
const sshdPath = "/usr/sbin/sshd";
const bashPath = "/bin/bash";
const zshPath = "/bin/zsh";
const oascriptPath = "/usr/bin/osascript";
const githubRunProvisionerScriptPath =
"/usr/local/opt/runner/runprovisioner.sh";
const githubProvisionerPath = "/usr/local/opt/runner/provisioner/provisioner";
const githubStartHCAScriptPath = "/opt/hca/start_hca.sh";
const githubHostedComputeAgentPath = "/opt/hca/hosted-compute-agent";
const circleciRunnerPath = "/private/tmp/.machine-agent";
const terminalApp = "com.apple.Terminal";
const voiceOverUtilityApp = "com.apple.VoiceOverUtility";
const voiceOverApp = "com.apple.VoiceOver";
const systemEventsApp = "com.apple.systemevents";
const finderApp = "com.apple.finder";
const safariApp = "com.apple.Safari";
const firefoxApp = "org.mozilla.firefox";
const firefoxNightlyApp = "org.mozilla.nightly";
const operaApp = "com.operasoftware.Opera";
const chromeApp = "com.google.Chrome";
const chromeBetaApp = "com.google.Chrome.beta";
const chromeForTestingApp = "com.google.chrome.for.testing";
const chromiumApp = "org.chromium.Chromium";
const edgeApp = "com.microsoft.edgemac";
const edgeBetaApp = "com.microsoft.edgemac.Beta";
const edgeDevApp = "com.microsoft.edgemac.Dev";
const playwrightWebkitApp = "org.webkit.Playwright";
const webkitApp = "com.apple.WebKit";
const getEntries = (): string[] => {
let gitlabRunnerPath: string;
try {
gitlabRunnerPath = execSync("which gitlab-runner", {
encoding: "utf8",
}).trim();
} catch {
gitlabRunnerPath = "/usr/local/bin/gitlab-runner";
}
const standardClients = [
sshdPath,
bashPath,
zshPath,
oascriptPath,
terminalApp,
githubRunProvisionerScriptPath,
githubProvisionerPath,
githubStartHCAScriptPath,
githubHostedComputeAgentPath,
gitlabRunnerPath,
circleciRunnerPath,
];
/**
* See https://www.rainforestqa.com/blog/macos-tcc-db-deep-dive for details on TCC.db entries.
*/
return [
// Permit Sending Keystrokes
...standardClients.map(
(client) =>
`'kTCCServicePostEvent','${client}',1,2,3,1,NULL,NULL,NULL,'UNUSED',NULL,0,${epoch}`,
),
// Permit Control Of Device
...standardClients.map(
(client) =>
`'kTCCServiceAccessibility','${client}',1,2,3,1,NULL,NULL,NULL,'UNUSED',NULL,0,${epoch}`,
),
// Permit Full Disk Access
...standardClients.map(
(client) =>
`'kTCCServiceSystemPolicyAllFiles','${client}',1,2,3,1,NULL,NULL,NULL,'UNUSED',NULL,0,${epoch}`,
),
// Permit Access To Microphone
...standardClients.map(
(client) =>
`'kTCCServiceMicrophone','${client}',1,2,3,1,NULL,NULL,NULL,'UNUSED',NULL,NULL,${epoch}`,
),
// Permit Capture Of System Display
...standardClients.map(
(client) =>
`'kTCCServiceScreenCapture','${client}',1,2,3,1,NULL,NULL,NULL,'UNUSED',NULL,0,${epoch}`,
),
// Permit VoiceOver Access To Location
`'kTCCServiceLiverpool','${voiceOverUtilityApp}',0,2,3,1,NULL,NULL,NULL,'UNUSED',NULL,0,${epoch}`,
`'kTCCServiceLiverpool','${voiceOverApp}',0,2,3,1,NULL,NULL,NULL,'UNUSED',NULL,0,${epoch}`,
// Permit VoiceOver Access To Bluetooth
`'kTCCServiceBluetoothAlways','${voiceOverApp}',0,2,3,1,NULL,NULL,NULL,'UNUSED',NULL,0,${epoch}`,
// Permit Control Of System Events
...standardClients.map(
(client) =>
`'kTCCServiceAppleEvents','${client}',1,2,3,1,NULL,NULL,0,'${systemEventsApp}',NULL,NULL,${epoch}`,
),
// Permit Control Of VoiceOver
...standardClients.map(
(client) =>
`'kTCCServiceAppleEvents','${client}',1,2,3,1,NULL,NULL,0,'${voiceOverApp}',NULL,NULL,${epoch}`,
),
// Permit Control Of VoiceOver Utility
...standardClients.map(
(client) =>
`'kTCCServiceAppleEvents','${client}',1,2,3,1,NULL,NULL,0,'${voiceOverUtilityApp}',NULL,NULL,${epoch}`,
),
// Permit Control Of Finder
...standardClients.map(
(client) =>
`'kTCCServiceAppleEvents','${client}',1,2,3,1,NULL,NULL,0,'${finderApp}',NULL,NULL,${epoch}`,
),
// Permit Control Of Safari
...standardClients.map(
(client) =>
`'kTCCServiceAppleEvents','${client}',1,2,3,1,NULL,NULL,0,'${safariApp}',NULL,NULL,${epoch}`,
),
// Permit Control Of Firefox
...standardClients.map(
(client) =>
`'kTCCServiceAppleEvents','${client}',1,2,3,1,NULL,NULL,0,'${firefoxApp}',NULL,NULL,${epoch}`,
),
// Permit Control Of Firefox Nightly And Playwright Firefox Nightly
...standardClients.map(
(client) =>
`'kTCCServiceAppleEvents','${client}',1,2,3,1,NULL,NULL,0,'${firefoxNightlyApp}',NULL,NULL,${epoch}`,
),
// Permit Control Of Opera
...standardClients.map(
(client) =>
`'kTCCServiceAppleEvents','${client}',1,2,3,1,NULL,NULL,0,'${operaApp}',NULL,NULL,${epoch}`,
),
// Permit Control Of Google Chrome
...standardClients.map(
(client) =>
`'kTCCServiceAppleEvents','${client}',1,2,3,1,NULL,NULL,0,'${chromeApp}',NULL,NULL,${epoch}`,
),
// Permit Control Of Google Chrome Beta
...standardClients.map(
(client) =>
`'kTCCServiceAppleEvents','${client}',1,2,3,1,NULL,NULL,0,'${chromeBetaApp}',NULL,NULL,${epoch}`,
),
// Permit Control Of Google Chrome For Testing
...standardClients.map(
(client) =>
`'kTCCServiceAppleEvents','${client}',1,2,3,1,NULL,NULL,0,'${chromeForTestingApp}',NULL,NULL,${epoch}`,
),
// Permit Control Of Chromium
...standardClients.map(
(client) =>
`'kTCCServiceAppleEvents','${client}',1,2,3,1,NULL,NULL,0,'${chromiumApp}',NULL,NULL,${epoch}`,
),
// Permit Control Of Microsoft Edge
...standardClients.map(
(client) =>
`'kTCCServiceAppleEvents','${client}',1,2,3,1,NULL,NULL,0,'${edgeApp}',NULL,NULL,${epoch}`,
),
// Permit Control Of Microsoft Edge Beta
...standardClients.map(
(client) =>
`'kTCCServiceAppleEvents','${client}',1,2,3,1,NULL,NULL,0,'${edgeBetaApp}',NULL,NULL,${epoch}`,
),
// Permit Control Of Microsoft Edge Dev
...standardClients.map(
(client) =>
`'kTCCServiceAppleEvents','${client}',1,2,3,1,NULL,NULL,0,'${edgeDevApp}',NULL,NULL,${epoch}`,
),
// Permit Control Of Playwright WebKit
...standardClients.map(
(client) =>
`'kTCCServiceAppleEvents','${client}',1,2,3,1,NULL,NULL,0,'${playwrightWebkitApp}',NULL,NULL,${epoch}`,
),
// Permit Control Of WebKit
...standardClients.map(
(client) =>
`'kTCCServiceAppleEvents','${client}',1,2,3,1,NULL,NULL,0,'${webkitApp}',NULL,NULL,${epoch}`,
),
];
};
export const USER_PATH =
"$HOME/Library/Application Support/com.apple.TCC/TCC.db";
export const SYSTEM_PATH = "/Library/Application Support/com.apple.TCC/TCC.db";
export function updateTccDb(path: string): void {
for (const values of getEntries()) {
const osRelease = release();
const isSonomaOrNewer = parseInt(osRelease.split(".").at(0)) >= 23;
const query = `INSERT OR IGNORE INTO access VALUES(${values}${
isSonomaOrNewer ? `,NULL,NULL,'UNUSED',${epoch}` : ""
});`;
try {
execSync(`sqlite3 "${path}" "${query}" >/dev/null 2>&1`, {
encoding: "utf8",
});
} catch (e) {
throw new Error(
`${ERR_MACOS_UNABLE_TO_WRITE_USER_TCC_DB}\n\n${e.message}`,
);
}
}
}