opal-security 3.2.4 → 4.0.2

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.
Files changed (149) hide show
  1. package/README.md +46 -61
  2. package/bin/dev +5 -5
  3. package/bin/run +2 -4
  4. package/build/commands/aws/identity.js +16 -0
  5. package/build/commands/clear-auth-config.d.ts +6 -0
  6. package/build/commands/clear-auth-config.js +22 -0
  7. package/{lib → build}/commands/groups/get.js +14 -16
  8. package/{lib → build}/commands/iam-roles/start.js +28 -30
  9. package/build/commands/kube-roles/start.js +71 -0
  10. package/{lib → build}/commands/login.d.ts +1 -0
  11. package/build/commands/login.js +379 -0
  12. package/build/commands/logout.js +22 -0
  13. package/{lib → build}/commands/postgres-instances/start.js +25 -27
  14. package/{lib → build}/commands/request/create.js +34 -36
  15. package/{lib → build}/commands/request/get.js +22 -24
  16. package/{lib → build}/commands/request/list.js +17 -19
  17. package/{lib → build}/commands/resources/get.js +15 -18
  18. package/build/commands/set-auth-config.d.ts +11 -0
  19. package/build/commands/set-auth-config.js +59 -0
  20. package/build/commands/set-custom-header.js +35 -0
  21. package/{lib → build}/commands/set-token.js +15 -17
  22. package/{lib → build}/commands/set-url.js +26 -28
  23. package/{lib → build}/commands/ssh/copyFrom.js +22 -24
  24. package/{lib → build}/commands/ssh/copyTo.js +22 -24
  25. package/{lib → build}/commands/ssh/start.js +30 -33
  26. package/build/commands/whoami.js +27 -0
  27. package/{lib → build}/graphql/fragment-masking.d.ts +1 -1
  28. package/{lib → build}/graphql/fragment-masking.js +3 -8
  29. package/{lib → build}/graphql/gql.d.ts +1 -1
  30. package/{lib → build}/graphql/gql.js +2 -5
  31. package/{lib → build}/graphql/graphql.js +256 -261
  32. package/build/graphql/index.d.ts +2 -0
  33. package/build/graphql/index.js +2 -0
  34. package/{lib → build}/handler.d.ts +1 -1
  35. package/build/handler.js +36 -0
  36. package/build/index.js +1 -0
  37. package/{lib → build}/labels.d.ts +1 -1
  38. package/build/labels.js +37 -0
  39. package/{lib → build}/lib/apollo.d.ts +2 -2
  40. package/{lib → build}/lib/apollo.js +62 -69
  41. package/build/lib/auth-success-template.d.ts +3 -0
  42. package/build/lib/auth-success-template.js +149 -0
  43. package/{lib → build}/lib/aws.js +2 -7
  44. package/{lib → build}/lib/cmd.d.ts +4 -4
  45. package/{lib → build}/lib/cmd.js +16 -20
  46. package/build/lib/config.js +46 -0
  47. package/{lib → build}/lib/credentials/index.d.ts +3 -2
  48. package/build/lib/credentials/index.js +85 -0
  49. package/{lib → build}/lib/credentials/keychain.js +4 -10
  50. package/{lib → build}/lib/credentials/localEncryption.js +12 -17
  51. package/{lib → build}/lib/flags.js +7 -10
  52. package/build/lib/local-auth-server.d.ts +5 -0
  53. package/build/lib/local-auth-server.js +69 -0
  54. package/build/lib/request/api/index.d.ts +6 -0
  55. package/build/lib/request/api/index.js +8 -0
  56. package/{lib → build}/lib/request/api/mutations/create-request.d.ts +2 -2
  57. package/{lib → build}/lib/request/api/mutations/create-request.js +3 -6
  58. package/{lib → build}/lib/request/api/queries/apps.d.ts +1 -1
  59. package/{lib → build}/lib/request/api/queries/apps.js +3 -6
  60. package/{lib → build}/lib/request/api/queries/assets.d.ts +2 -2
  61. package/{lib → build}/lib/request/api/queries/assets.js +7 -11
  62. package/{lib → build}/lib/request/api/queries/request-defaults.d.ts +2 -2
  63. package/{lib → build}/lib/request/api/queries/request-defaults.js +3 -6
  64. package/{lib → build}/lib/request/api/queries/requests.d.ts +3 -3
  65. package/{lib → build}/lib/request/api/queries/requests.js +10 -16
  66. package/{lib → build}/lib/request/api/queries/roles.d.ts +1 -1
  67. package/{lib → build}/lib/request/api/queries/roles.js +14 -18
  68. package/{lib → build}/lib/request/displays.d.ts +2 -2
  69. package/{lib → build}/lib/request/displays.js +27 -37
  70. package/{lib → build}/lib/request/prompts/apps-prompt.d.ts +1 -1
  71. package/build/lib/request/prompts/apps-prompt.js +33 -0
  72. package/{lib → build}/lib/request/prompts/asset-prompt.d.ts +1 -1
  73. package/build/lib/request/prompts/asset-prompt.js +61 -0
  74. package/{lib → build}/lib/request/prompts/duration-prompt.d.ts +1 -1
  75. package/{lib → build}/lib/request/prompts/duration-prompt.js +6 -10
  76. package/build/lib/request/prompts/index.d.ts +7 -0
  77. package/build/lib/request/prompts/index.js +8 -0
  78. package/{lib → build}/lib/request/prompts/reason-prompt.d.ts +1 -1
  79. package/{lib → build}/lib/request/prompts/reason-prompt.js +3 -6
  80. package/{lib → build}/lib/request/prompts/role-prompt.d.ts +1 -1
  81. package/{lib → build}/lib/request/prompts/role-prompt.js +9 -11
  82. package/{lib → build}/lib/request/prompts/validate-prompt.d.ts +1 -1
  83. package/{lib → build}/lib/request/prompts/validate-prompt.js +9 -13
  84. package/{lib → build}/lib/request/request-utils.d.ts +2 -2
  85. package/{lib → build}/lib/request/request-utils.js +50 -62
  86. package/{lib → build}/lib/request/types.d.ts +1 -1
  87. package/build/lib/request/types.js +12 -0
  88. package/{lib → build}/lib/resources.d.ts +1 -1
  89. package/{lib → build}/lib/resources.js +18 -23
  90. package/{lib → build}/lib/sessions.d.ts +1 -1
  91. package/{lib → build}/lib/sessions.js +57 -32
  92. package/{lib → build}/lib/ssh.d.ts +1 -1
  93. package/{lib → build}/lib/ssh.js +6 -11
  94. package/{lib → build}/lib/util.js +7 -14
  95. package/{lib → build}/types.js +98 -101
  96. package/oclif.manifest.json +77 -98
  97. package/package.json +24 -14
  98. package/lib/commands/aws/identity.js +0 -18
  99. package/lib/commands/clear-auth-provider.d.ts +0 -9
  100. package/lib/commands/clear-auth-provider.js +0 -28
  101. package/lib/commands/curl-example.d.ts +0 -8
  102. package/lib/commands/curl-example.js +0 -34
  103. package/lib/commands/kube-roles/start.js +0 -73
  104. package/lib/commands/login.js +0 -286
  105. package/lib/commands/logout.js +0 -23
  106. package/lib/commands/set-auth-provider.d.ts +0 -11
  107. package/lib/commands/set-auth-provider.js +0 -44
  108. package/lib/commands/set-custom-header.js +0 -37
  109. package/lib/commands/whoami.js +0 -34
  110. package/lib/graphql/index.d.ts +0 -2
  111. package/lib/graphql/index.js +0 -5
  112. package/lib/handler.js +0 -41
  113. package/lib/index.js +0 -5
  114. package/lib/labels.js +0 -40
  115. package/lib/lib/config.js +0 -54
  116. package/lib/lib/credentials/index.js +0 -67
  117. package/lib/lib/request/api/index.d.ts +0 -6
  118. package/lib/lib/request/api/index.js +0 -20
  119. package/lib/lib/request/prompts/apps-prompt.js +0 -35
  120. package/lib/lib/request/prompts/asset-prompt.js +0 -65
  121. package/lib/lib/request/prompts/index.d.ts +0 -7
  122. package/lib/lib/request/prompts/index.js +0 -19
  123. package/lib/lib/request/types.js +0 -15
  124. /package/{lib → build}/commands/aws/identity.d.ts +0 -0
  125. /package/{lib → build}/commands/groups/get.d.ts +0 -0
  126. /package/{lib → build}/commands/iam-roles/start.d.ts +0 -0
  127. /package/{lib → build}/commands/kube-roles/start.d.ts +0 -0
  128. /package/{lib → build}/commands/logout.d.ts +0 -0
  129. /package/{lib → build}/commands/postgres-instances/start.d.ts +0 -0
  130. /package/{lib → build}/commands/request/create.d.ts +0 -0
  131. /package/{lib → build}/commands/request/get.d.ts +0 -0
  132. /package/{lib → build}/commands/request/list.d.ts +0 -0
  133. /package/{lib → build}/commands/resources/get.d.ts +0 -0
  134. /package/{lib → build}/commands/set-custom-header.d.ts +0 -0
  135. /package/{lib → build}/commands/set-token.d.ts +0 -0
  136. /package/{lib → build}/commands/set-url.d.ts +0 -0
  137. /package/{lib → build}/commands/ssh/copyFrom.d.ts +0 -0
  138. /package/{lib → build}/commands/ssh/copyTo.d.ts +0 -0
  139. /package/{lib → build}/commands/ssh/start.d.ts +0 -0
  140. /package/{lib → build}/commands/whoami.d.ts +0 -0
  141. /package/{lib → build}/graphql/graphql.d.ts +0 -0
  142. /package/{lib → build}/index.d.ts +0 -0
  143. /package/{lib → build}/lib/aws.d.ts +0 -0
  144. /package/{lib → build}/lib/config.d.ts +0 -0
  145. /package/{lib → build}/lib/credentials/keychain.d.ts +0 -0
  146. /package/{lib → build}/lib/credentials/localEncryption.d.ts +0 -0
  147. /package/{lib → build}/lib/flags.d.ts +0 -0
  148. /package/{lib → build}/lib/util.d.ts +0 -0
  149. /package/{lib → build}/types.d.ts +0 -0
@@ -1,286 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CLITokenExchangeName = exports.CLIAuthSessionCheckDocument = exports.CLIAuthSessionCheckName = exports.CLISignInMethodName = void 0;
4
- const core_1 = require("@oclif/core");
5
- const open = require("open");
6
- const openid_client_1 = require("openid-client");
7
- const client_1 = require("@apollo/client");
8
- const inquirer = require("inquirer");
9
- const handler_1 = require("../handler");
10
- const apollo_1 = require("../lib/apollo");
11
- const config_1 = require("../lib/config");
12
- const credentials_1 = require("../lib/credentials");
13
- const flags_1 = require("../lib/flags");
14
- const util_1 = require("../lib/util");
15
- const ISSUER_PROD = "https://auth.opal.dev";
16
- const ISSUER_DEV = "https://authdev.opal.dev";
17
- const GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
18
- const CLIENT_ID_PROD = "42rm6E5v7o67LBpRfjdT9KhnjrQHr9UF";
19
- const CLIENT_ID_DEV = "XYV8qoAvZG7dHnhRp2g5XMJ1zX9fBP6s";
20
- const CLISignInMethodDocumentLegacy = `
21
- query CLISignInMethod($input: SignInMethodInput!) {
22
- signInMethod(input: $input) {
23
- __typename
24
- ... on SignInMethodResult {
25
- signInOrganizations {
26
- organizationId
27
- organizationName
28
- }
29
- }
30
- }
31
- }`;
32
- exports.CLISignInMethodName = "CLISignInMethod";
33
- const CLISignInMethodDocument = `
34
- query CLISignInMethod($input: SignInMethodInput!) {
35
- signInMethod(input: $input) {
36
- __typename
37
- ... on SignInMethodResult {
38
- signInOrganizations {
39
- organizationId
40
- organizationName
41
- cliClientId
42
- }
43
- }
44
- }
45
- }`;
46
- exports.CLIAuthSessionCheckName = "CLIAuthSessionCheck";
47
- exports.CLIAuthSessionCheckDocument = `
48
- query CLIAuthSessionCheck {
49
- organizationSettings {
50
- ... on OrganizationSettingsResult {
51
- settings {
52
- id
53
- }
54
- }
55
- }
56
- }
57
- `;
58
- const SignInDocument = `
59
- mutation SignIn($input: SignInInput!) {
60
- signIn(input: $input) {
61
- __typename
62
- ... on SignInResult {
63
- state
64
- forceExtraStep
65
- authURL
66
- __typename
67
- }
68
- }
69
- }
70
- `;
71
- exports.CLITokenExchangeName = "CLITokenExchange";
72
- const CLITokenExchangeDocument = `
73
- mutation CLITokenExchange($input: CLITokenExchangeInput!) {
74
- cliTokenExchange(input: $input) {
75
- __typename
76
- ... on CLITokenExchangeOutput {
77
- sessionID
78
- }
79
- }
80
- }
81
- `;
82
- class Login extends core_1.Command {
83
- async run() {
84
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
85
- try {
86
- await (0, apollo_1.initClient)(this, false);
87
- const { flags } = await this.parse(Login);
88
- const configDir = this.config.configDir;
89
- const configData = (0, config_1.getOrCreateConfigData)(configDir);
90
- let email = flags.email;
91
- let organizationId;
92
- let organizationName;
93
- let clientIDCandidate;
94
- const existingCreds = await (0, credentials_1.getOpalCredentials)(this, false);
95
- // Only use the previous email + organizationID if email isn't explicitly specified.
96
- if (!email) {
97
- email = existingCreds.email;
98
- organizationId = existingCreds.organizationID;
99
- organizationName = existingCreds.organizationName;
100
- clientIDCandidate = existingCreds.clientIDCandidate;
101
- }
102
- await (0, credentials_1.removeOpalCredentials)(this);
103
- this.log("Welcome to Opal! ⚡\n");
104
- this.log("Connecting to Opal server URL:", configData[config_1.urlKey]);
105
- this.log("If this is incorrect, please run `opal set-url --help`\n");
106
- if (email) {
107
- this.log(`Signing in as: ${email} - to use a different account, run \`opal login --email [EMAIL]\``);
108
- }
109
- else {
110
- const { email: promptEmail } = await inquirer.prompt([
111
- {
112
- name: "email",
113
- message: "Enter your email:",
114
- type: "input",
115
- validate: (email) => Boolean(email),
116
- },
117
- ]);
118
- email = promptEmail;
119
- }
120
- if (!organizationId) {
121
- let signInOrganizationsLegacyResponse;
122
- const { resp: signInOrganizationsResponse, error } = await (0, handler_1.runQueryDeprecated)({
123
- command: this,
124
- query: CLISignInMethodDocument,
125
- variables: { input: { email } },
126
- });
127
- if (error) {
128
- if (client_1.ServerError.is(error) && error.statusCode === 422) {
129
- const { resp, error: legacyError } = await (0, handler_1.runQueryDeprecated)({
130
- command: this,
131
- query: CLISignInMethodDocumentLegacy,
132
- variables: { input: { email } },
133
- });
134
- signInOrganizationsLegacyResponse = resp;
135
- if (legacyError) {
136
- this.log(""); // Intentional newline
137
- return (0, apollo_1.handleError)(this, "Could not connect to Opal. Did you set the right URL? (`opal set-url --help`)");
138
- }
139
- }
140
- else {
141
- this.log(""); // Intentional newline
142
- return (0, apollo_1.handleError)(this, "Could not connect to Opal. Did you set the right URL? (`opal set-url --help`)");
143
- }
144
- }
145
- const signInOrganizations = ((_b = (_a = signInOrganizationsResponse === null || signInOrganizationsResponse === void 0 ? void 0 : signInOrganizationsResponse.data) === null || _a === void 0 ? void 0 : _a.signInMethod) === null || _b === void 0 ? void 0 : _b.__typename) ===
146
- "SignInMethodResult"
147
- ? signInOrganizationsResponse.data.signInMethod.signInOrganizations
148
- : ((_d = (_c = signInOrganizationsLegacyResponse === null || signInOrganizationsLegacyResponse === void 0 ? void 0 : signInOrganizationsLegacyResponse.data) === null || _c === void 0 ? void 0 : _c.signInMethod) === null || _d === void 0 ? void 0 : _d.__typename) === "SignInMethodResult"
149
- ? (_e = signInOrganizationsLegacyResponse === null || signInOrganizationsLegacyResponse === void 0 ? void 0 : signInOrganizationsLegacyResponse.data.signInMethod) === null || _e === void 0 ? void 0 : _e.signInOrganizations
150
- : undefined;
151
- if (signInOrganizations && signInOrganizations.length > 0) {
152
- if (signInOrganizations.length === 1) {
153
- organizationId = signInOrganizations[0].organizationId;
154
- organizationName = signInOrganizations[0].organizationName;
155
- clientIDCandidate = signInOrganizations[0].cliClientId;
156
- }
157
- else {
158
- const responses = await inquirer.prompt([
159
- {
160
- name: "signInOrganization",
161
- message: "Select an organization:",
162
- type: "list",
163
- choices: signInOrganizations.map((signInOrganization) => ({
164
- name: signInOrganization === null || signInOrganization === void 0 ? void 0 : signInOrganization.organizationName,
165
- value: signInOrganization,
166
- })),
167
- },
168
- ]);
169
- organizationId = responses.signInOrganization.organizationId;
170
- organizationName = responses.signInOrganization.organizationName;
171
- clientIDCandidate = responses.signInOrganization.cliClientId;
172
- }
173
- }
174
- else {
175
- // If there are no organizations for the user, require the user to login before failing,
176
- // which is parity with our web app.
177
- }
178
- }
179
- const { resp: signInResp } = await (0, handler_1.runMutation)({
180
- command: this,
181
- query: SignInDocument,
182
- variables: {
183
- input: { organizationId },
184
- },
185
- });
186
- const state = (_g = (_f = signInResp === null || signInResp === void 0 ? void 0 : signInResp.data) === null || _f === void 0 ? void 0 : _f.signIn) === null || _g === void 0 ? void 0 : _g.state;
187
- let issuer;
188
- // issuerURL may come from configData if set by set-airgap-auth
189
- if (configData.issuerURL) {
190
- issuer = await openid_client_1.Issuer.discover(configData.issuerURL);
191
- }
192
- else if ((0, config_1.isProduction)(this.config.configDir)) {
193
- issuer = await openid_client_1.Issuer.discover(ISSUER_PROD);
194
- }
195
- else {
196
- issuer = await openid_client_1.Issuer.discover(ISSUER_DEV);
197
- }
198
- let clientID;
199
- if (clientIDCandidate) {
200
- // clientIdCandidate gets stored in creds, and is mostly relevant for on-prem envs using Auth0 and SAML
201
- clientID = clientIDCandidate;
202
- }
203
- else if (configData.clientID) {
204
- // clientID may come from configData if set by set-airgap-auth
205
- clientID = configData.clientID;
206
- }
207
- else if ((0, config_1.isProduction)(this.config.configDir)) {
208
- clientID = CLIENT_ID_PROD;
209
- }
210
- else {
211
- clientID = CLIENT_ID_DEV;
212
- }
213
- const client = new issuer.Client({
214
- grant_types: [GRANT_TYPE],
215
- client_id: clientID,
216
- response_types: [],
217
- redirect_uris: [],
218
- token_endpoint_auth_method: "none",
219
- application_type: "native",
220
- });
221
- // Add the mfa:skip scope to the scopes according to appropriate org settings
222
- // This scope is evaluated in Auth0 "MFA Rule" Action to skip or enabled MFA
223
- let scopes = "openid email profile";
224
- if (!((_j = (_h = signInResp === null || signInResp === void 0 ? void 0 : signInResp.data) === null || _h === void 0 ? void 0 : _h.signIn) === null || _j === void 0 ? void 0 : _j.forceExtraStep)) {
225
- scopes += " mfa:skip";
226
- }
227
- const handle = await client.deviceAuthorization({
228
- audience: "https://opal.dev",
229
- scope: scopes,
230
- });
231
- this.log("\nYou are being redirected to your browser to authenticate.\n");
232
- this.log(` User Code: ${handle.user_code}\n`);
233
- this.log("If your browser doesn't open, go to:", handle.verification_uri_complete, "\n");
234
- // Wait before opening the browser window to ensure the user has time to
235
- // see the User Code.
236
- await (0, util_1.sleep)(1000);
237
- await open(handle.verification_uri_complete, { wait: false });
238
- const tokenSet = await handle.poll();
239
- const { error: tokenExchangeError } = await (0, handler_1.runMutation)({
240
- command: this,
241
- query: CLITokenExchangeDocument,
242
- variables: {
243
- input: {
244
- accessToken: tokenSet === null || tokenSet === void 0 ? void 0 : tokenSet.access_token,
245
- state,
246
- },
247
- },
248
- });
249
- if (tokenExchangeError) {
250
- this.log("WARN: Failed to exchange access token for session in Opal. Falling back to using access token for authenticating requests\n");
251
- // TODO: consider adding a warn line recommending upgrading Opal to version XYZ, once accompanying PR is pushed to prod
252
- await (0, credentials_1.setOpalCredentials)(this, email, organizationId !== null && organizationId !== void 0 ? organizationId : "", clientIDCandidate, (tokenSet === null || tokenSet === void 0 ? void 0 : tokenSet.access_token) || "", credentials_1.SecretType.ApiToken, organizationName);
253
- }
254
- else {
255
- await (0, credentials_1.setOpalCredentials)(this, email, organizationId !== null && organizationId !== void 0 ? organizationId : "", clientIDCandidate, apollo_1.cookieStr, credentials_1.SecretType.Cookie, organizationName);
256
- }
257
- // "Representative" authenticated call to check the log-in worked as expected.
258
- const { resp: authCheckResp, error: authCheckErr } = await (0, handler_1.runQueryDeprecated)({
259
- command: this,
260
- query: exports.CLIAuthSessionCheckDocument,
261
- variables: {},
262
- });
263
- if (authCheckErr ||
264
- !((_m = (_l = (_k = authCheckResp === null || authCheckResp === void 0 ? void 0 : authCheckResp.data) === null || _k === void 0 ? void 0 : _k.organizationSettings) === null || _l === void 0 ? void 0 : _l.settings) === null || _m === void 0 ? void 0 : _m.id)) {
265
- this.log("Error verifying log in. Authenticated commands may fail. Please double check your URL and use `opal logout; opal login` to try again.\n");
266
- await (0, credentials_1.removeOpalCredentials)(this);
267
- process.exit(1);
268
- }
269
- this.log("🎉 You have successfully authenticated with Opal! You can now run authenticated commands.\n");
270
- }
271
- catch (error) {
272
- this.error(error);
273
- }
274
- }
275
- }
276
- Login.description = "Authenticates you with the Opal server.";
277
- Login.examples = ["$ opal login"];
278
- Login.flags = {
279
- help: flags_1.SHARED_FLAGS.help,
280
- email: core_1.Flags.string({
281
- multiple: false,
282
- description: "Email address to login with.",
283
- }),
284
- };
285
- Login.args = {};
286
- exports.default = Login;
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const core_1 = require("@oclif/core");
4
- const credentials_1 = require("../lib/credentials");
5
- const flags_1 = require("../lib/flags");
6
- class Logout extends core_1.Command {
7
- async run() {
8
- try {
9
- await (0, credentials_1.removeOpalCredentials)(this);
10
- this.log("Successfully removed the saved Account ID and Auth Token from this computer");
11
- }
12
- catch (error) {
13
- this.error(error);
14
- }
15
- }
16
- }
17
- Logout.description = "Clears locally stored Opal server authentication credentials.";
18
- Logout.examples = ["$ opal logout"];
19
- Logout.flags = {
20
- help: flags_1.SHARED_FLAGS.help,
21
- };
22
- Logout.args = {};
23
- exports.default = Logout;
@@ -1,11 +0,0 @@
1
- import { Command } from "@oclif/core";
2
- export default class SetAuthProvider extends Command {
3
- static description: string;
4
- static examples: string[];
5
- static flags: {
6
- help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
7
- clientID: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
8
- issuerUrl: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
9
- };
10
- run(): Promise<void>;
11
- }
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const core_1 = require("@oclif/core");
4
- const config_1 = require("../lib/config");
5
- const credentials_1 = require("../lib/credentials");
6
- const flags_1 = require("../lib/flags");
7
- class SetAuthProvider extends core_1.Command {
8
- async run() {
9
- try {
10
- const { flags, args } = await this.parse(SetAuthProvider);
11
- const configData = (0, config_1.getOrCreateConfigData)(this.config.configDir);
12
- configData.issuerURL = flags.issuerUrl;
13
- configData.clientID = flags.clientID;
14
- (0, config_1.writeConfigData)(this.config.configDir, configData);
15
- await (0, credentials_1.removeOpalCredentials)(this);
16
- this.log("Client ID and Issuer URL updated");
17
- }
18
- catch (error) {
19
- this.error(error);
20
- }
21
- }
22
- }
23
- SetAuthProvider.description = `Sets the Issuer URL and Client ID of the Auth Provider that the CLI will authenticate with.
24
- Only use this if you are running a self-hosted, air-gapped instance of Opal that uses a custom Auth Provider.
25
-
26
- Note - you will need an OIDC provider that supports the device_code grant.
27
- `;
28
- SetAuthProvider.examples = [
29
- "$ opal set-auth-provider --clientID 1234asdf --issuerUrl https://auth.example.com",
30
- ];
31
- SetAuthProvider.flags = {
32
- help: flags_1.SHARED_FLAGS.help,
33
- clientID: core_1.Flags.string({
34
- multiple: false,
35
- description: "Client ID of your Auth Provider",
36
- required: true,
37
- }),
38
- issuerUrl: core_1.Flags.string({
39
- multiple: false,
40
- description: "Issuer URL of your Auth Provider",
41
- required: true,
42
- }),
43
- };
44
- exports.default = SetAuthProvider;
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const core_1 = require("@oclif/core");
4
- const apollo_1 = require("../lib/apollo");
5
- const config_1 = require("../lib/config");
6
- const flags_1 = require("../lib/flags");
7
- class SetCustomHeader extends core_1.Command {
8
- async run() {
9
- try {
10
- const { flags } = await this.parse(SetCustomHeader);
11
- let header;
12
- if (flags.header) {
13
- header = flags.header;
14
- }
15
- const configData = (0, config_1.getOrCreateConfigData)(this.config.configDir);
16
- configData[config_1.customHttpHeaderKey] = header;
17
- (0, config_1.writeConfigData)(this.config.configDir, configData);
18
- await (0, apollo_1.initClient)(this);
19
- this.log("Custom HTTP header updated");
20
- }
21
- catch (error) {
22
- this.error(error);
23
- }
24
- }
25
- }
26
- SetCustomHeader.description = "Sets a custom HTTP header to connect to the Opal server.";
27
- SetCustomHeader.examples = [
28
- "$ opal set-custom-header --header 'cf-access-token: $TOKEN'",
29
- ];
30
- SetCustomHeader.flags = {
31
- help: flags_1.SHARED_FLAGS.help,
32
- header: core_1.Flags.string({
33
- multiple: false,
34
- }),
35
- };
36
- SetCustomHeader.args = {};
37
- exports.default = SetCustomHeader;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const core_1 = require("@oclif/core");
4
- const config_1 = require("../lib/config");
5
- const credentials_1 = require("../lib/credentials");
6
- const flags_1 = require("../lib/flags");
7
- class WhoAmI extends core_1.Command {
8
- async run() {
9
- const opalCreds = await (0, credentials_1.getOpalCredentials)(this, false);
10
- const organizationName = opalCreds === null || opalCreds === void 0 ? void 0 : opalCreds.organizationName;
11
- const email = opalCreds === null || opalCreds === void 0 ? void 0 : opalCreds.email;
12
- const configData = (0, config_1.getOrCreateConfigData)(this.config.configDir);
13
- const url = configData[config_1.urlKey];
14
- if (email) {
15
- this.log(`User: ${email}`);
16
- }
17
- if (organizationName) {
18
- if (organizationName === "unset-org-id") {
19
- this.log("Authenticated with Opal API Token.");
20
- }
21
- else {
22
- this.log(`Organization: ${organizationName}`);
23
- }
24
- }
25
- if (url) {
26
- this.log(`Server: ${url}`);
27
- }
28
- }
29
- }
30
- WhoAmI.description = "Describes current url set, organization name, and logged in user if applicable.";
31
- WhoAmI.flags = {
32
- help: flags_1.SHARED_FLAGS.help,
33
- };
34
- exports.default = WhoAmI;
@@ -1,2 +0,0 @@
1
- export * from "./fragment-masking";
2
- export * from "./gql";
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./fragment-masking"), exports);
5
- tslib_1.__exportStar(require("./gql"), exports);
package/lib/handler.js DELETED
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runQueryDeprecated = exports.runMutation = void 0;
4
- const graphql_tag_1 = require("graphql-tag");
5
- const apollo_1 = require("./lib/apollo");
6
- const runMutation = async ({ command, query, variables, }) => {
7
- await (0, apollo_1.initClient)(command);
8
- let mutationResp = undefined;
9
- let mutationError = null;
10
- try {
11
- mutationResp = await (apollo_1.client === null || apollo_1.client === void 0 ? void 0 : apollo_1.client.mutate({
12
- mutation: (0, graphql_tag_1.default) `
13
- ${query}
14
- `,
15
- variables: variables,
16
- }));
17
- }
18
- catch (error) {
19
- mutationError = error;
20
- }
21
- return { resp: mutationResp, error: mutationError };
22
- };
23
- exports.runMutation = runMutation;
24
- const runQueryDeprecated = async ({ command, query, variables, }) => {
25
- await (0, apollo_1.initClient)(command);
26
- let queryResp = null;
27
- let queryError = null;
28
- try {
29
- queryResp = await (apollo_1.client === null || apollo_1.client === void 0 ? void 0 : apollo_1.client.query({
30
- query: (0, graphql_tag_1.default) `
31
- ${query}
32
- `,
33
- variables: variables,
34
- }));
35
- }
36
- catch (error) {
37
- queryError = error;
38
- }
39
- return { resp: queryResp, error: queryError };
40
- };
41
- exports.runQueryDeprecated = runQueryDeprecated;
package/lib/index.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.run = void 0;
4
- var core_1 = require("@oclif/core");
5
- Object.defineProperty(exports, "run", { enumerable: true, get: function () { return core_1.run; } });
package/lib/labels.js DELETED
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DisplayLabels = exports.connectionTypeLabelByType = void 0;
4
- const graphql_1 = require("./graphql/graphql");
5
- exports.connectionTypeLabelByType = {
6
- [graphql_1.ConnectionType.ActiveDirectory]: "Active Directory",
7
- [graphql_1.ConnectionType.Aws]: "Amazon Web Services (Legacy)",
8
- [graphql_1.ConnectionType.AwsSso]: "Amazon Web Services",
9
- [graphql_1.ConnectionType.Custom]: "Custom Integration",
10
- [graphql_1.ConnectionType.CustomConnector]: "Custom App Connector",
11
- [graphql_1.ConnectionType.Duo]: "Duo",
12
- [graphql_1.ConnectionType.Gcp]: "Google Cloud Platform",
13
- [graphql_1.ConnectionType.GitHub]: "GitHub",
14
- [graphql_1.ConnectionType.GitLab]: "GitLab",
15
- [graphql_1.ConnectionType.GoogleGroups]: "Google Groups",
16
- [graphql_1.ConnectionType.GoogleWorkspace]: "Google Workspace",
17
- [graphql_1.ConnectionType.Ldap]: "LDAP",
18
- [graphql_1.ConnectionType.Mongo]: "MongoDB Database",
19
- [graphql_1.ConnectionType.MongoAtlas]: "MongoDB Atlas Database",
20
- [graphql_1.ConnectionType.OktaDirectory]: "Okta Directory",
21
- [graphql_1.ConnectionType.Opal]: "Opal",
22
- [graphql_1.ConnectionType.Pagerduty]: "PagerDuty",
23
- [graphql_1.ConnectionType.Tailscale]: "Tailscale",
24
- [graphql_1.ConnectionType.Salesforce]: "Salesforce",
25
- [graphql_1.ConnectionType.Workday]: "Workday",
26
- [graphql_1.ConnectionType.Mysql]: "MySQL",
27
- [graphql_1.ConnectionType.Mariadb]: "MariaDB",
28
- [graphql_1.ConnectionType.Postgres]: "PostgreSQL",
29
- [graphql_1.ConnectionType.Teleport]: "Teleport",
30
- [graphql_1.ConnectionType.AzureAd]: "Azure",
31
- [graphql_1.ConnectionType.Snowflake]: "Snowflake",
32
- [graphql_1.ConnectionType.Databricks]: "Databricks",
33
- [graphql_1.ConnectionType.Coupa]: "Coupa",
34
- [graphql_1.ConnectionType.DatastaxAstra]: "DataStax Astra",
35
- [graphql_1.ConnectionType.Ilevel]: "iLEVEL",
36
- };
37
- exports.DisplayLabels = {
38
- [graphql_1.EntityType.Resource]: "Resource",
39
- [graphql_1.EntityType.Group]: "Group",
40
- };
package/lib/lib/config.js DELETED
@@ -1,54 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isProduction = exports.writeConfigData = exports.getOrCreateConfigData = exports.customHttpHeaderKey = exports.defaultAllowSelfSignedCerts = exports.allowSelfSignedCertsKey = exports.defaultUrl = exports.urlKey = void 0;
4
- const fs = require("node:fs");
5
- const path = require("node:path");
6
- exports.urlKey = "url";
7
- exports.defaultUrl = "https://app.opal.dev";
8
- exports.allowSelfSignedCertsKey = "allowSelfSignedCerts";
9
- exports.defaultAllowSelfSignedCerts = false;
10
- exports.customHttpHeaderKey = "customHttpHeader";
11
- const getOrCreateConfigData = (configDir) => {
12
- if (!fs.existsSync(configDir)) {
13
- fs.mkdirSync(configDir, { recursive: true });
14
- }
15
- const configFilePath = path.join(configDir, "config.json");
16
- if (!fs.existsSync(configFilePath)) {
17
- fs.writeFileSync(configFilePath, JSON.stringify({
18
- [exports.urlKey]: exports.defaultUrl,
19
- [exports.allowSelfSignedCertsKey]: exports.defaultAllowSelfSignedCerts,
20
- }));
21
- }
22
- let configData = {};
23
- try {
24
- const configDataRaw = fs.readFileSync(configFilePath);
25
- configData = JSON.parse(configDataRaw === null || configDataRaw === void 0 ? void 0 : configDataRaw.toString());
26
- }
27
- catch (error) {
28
- if (error.code !== "ENOENT") {
29
- throw error;
30
- }
31
- }
32
- return configData;
33
- };
34
- exports.getOrCreateConfigData = getOrCreateConfigData;
35
- const writeConfigData = (configDir, newConfigData) => {
36
- const existingData = (0, exports.getOrCreateConfigData)(configDir);
37
- for (const [key, value] of Object.entries(newConfigData)) {
38
- existingData[key] = value;
39
- }
40
- const configFilePath = path.join(configDir, "config.json");
41
- fs.writeFileSync(configFilePath, JSON.stringify(existingData), {
42
- mode: 0o0600,
43
- });
44
- };
45
- exports.writeConfigData = writeConfigData;
46
- const isProduction = (configDir) => {
47
- const configData = (0, exports.getOrCreateConfigData)(configDir);
48
- // Custom URLs are considered production since it includes on-prem
49
- return (configData[exports.urlKey] !== "https://dev.opal.dev" &&
50
- configData[exports.urlKey] !== "https://demo.opal.dev" &&
51
- configData[exports.urlKey] !== "https://staging.opal.dev" &&
52
- !configData[exports.urlKey].match(/https?:\/\/localhost/));
53
- };
54
- exports.isProduction = isProduction;
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removeOpalCredentials = exports.getOpalCredentials = exports.setOpalCredentials = exports.SecretType = void 0;
4
- const config_1 = require("../config");
5
- const keychain_1 = require("./keychain");
6
- const localEncryption_1 = require("./localEncryption");
7
- var SecretType;
8
- (function (SecretType) {
9
- SecretType["Cookie"] = "COOKIE";
10
- SecretType["ApiToken"] = "API_TOKEN";
11
- })(SecretType || (exports.SecretType = SecretType = {}));
12
- const setOpalCredentials = async (command, email, organizationID, clientIDCandidate, secret, secretType, organizationName) => {
13
- const givenEmail = email || "email-unset";
14
- const configData = (0, config_1.getOrCreateConfigData)(command.config.configDir);
15
- configData.creds = {
16
- clientIDCandidate,
17
- email,
18
- organizationID,
19
- organizationName,
20
- secretType,
21
- };
22
- (0, config_1.writeConfigData)(command.config.configDir, configData);
23
- if (process.platform === "darwin") {
24
- await (0, keychain_1.setSecretInKeychain)(givenEmail, secret);
25
- }
26
- else {
27
- await (0, localEncryption_1.setSecretInConfig)(command, configData, secret);
28
- }
29
- };
30
- exports.setOpalCredentials = setOpalCredentials;
31
- const getOpalCredentials = async (command, includeAuthSecret = true) => {
32
- var _a, _b;
33
- const creds = (_b = (_a = (0, config_1.getOrCreateConfigData)(command.config.configDir)) === null || _a === void 0 ? void 0 : _a.creds) !== null && _b !== void 0 ? _b : {};
34
- if (!includeAuthSecret) {
35
- return creds;
36
- }
37
- let secret = null;
38
- if (process.platform === "darwin") {
39
- secret = await (0, keychain_1.getSecretFromKeychain)((creds === null || creds === void 0 ? void 0 : creds.email) || "email-unset");
40
- }
41
- else {
42
- secret = await (0, localEncryption_1.getSecretFromConfig)(creds);
43
- }
44
- if (secret) {
45
- creds.secret = secret;
46
- // This is a fallback for users with stored credentials from before we converted to session auth with the CLITokenExchange mutation
47
- // It will allow them to continue authenticating with an access token in an Authorization header, which will work until we remove support for that
48
- if (!creds.secretType) {
49
- creds.secretType = SecretType.ApiToken;
50
- }
51
- }
52
- return creds;
53
- };
54
- exports.getOpalCredentials = getOpalCredentials;
55
- const removeOpalCredentials = async (command) => {
56
- var _a;
57
- const configData = (0, config_1.getOrCreateConfigData)(command.config.configDir);
58
- const email = ((_a = configData === null || configData === void 0 ? void 0 : configData.creds) === null || _a === void 0 ? void 0 : _a.email) || "email-unset";
59
- // On linux, the access token is stored encrypted in configData.creds, so this effectively removes it
60
- configData.creds = {};
61
- (0, config_1.writeConfigData)(command.config.configDir, configData);
62
- // but on OSX, we need an extra step to delete the token from the keychain
63
- if (process.platform === "darwin") {
64
- await (0, keychain_1.deleteSecretFromKeychain)(email);
65
- }
66
- };
67
- exports.removeOpalCredentials = removeOpalCredentials;
@@ -1,6 +0,0 @@
1
- export { queryRequestableApps } from "./queries/apps";
2
- export { queryRequestableAssets, queryCatalogItems } from "./queries/assets";
3
- export { queryAssetRoles, queryAssociatedItems } from "./queries/roles";
4
- export { queryRequestDefaults } from "./queries/request-defaults";
5
- export { queryRequest, queryRequests } from "./queries/requests";
6
- export { createRequest } from "./mutations/create-request";