aspera-cli 4.27.5 → 4.29.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/BUGS.md +5 -10
- data/CHANGELOG.md +301 -4
- data/CODE_OF_CONDUCT.md +18 -0
- data/CONTRIBUTING.md +139 -58
- data/GOVERNANCE.md +30 -0
- data/LICENSE +201 -0
- data/README.md +103 -26
- data/SECURITY.md +70 -0
- data/bin/ascli +8 -5
- data/bin/asession +10 -7
- data/docs/README.md +2551 -772
- data/docs/test-mcp-with-ai.md +13 -11
- data/lib/aspera/agent/base.rb +23 -2
- data/lib/aspera/agent/connect.rb +16 -12
- data/lib/aspera/agent/desktop.rb +10 -7
- data/lib/aspera/agent/direct.rb +34 -22
- data/lib/aspera/agent/factory.rb +8 -4
- data/lib/aspera/agent/httpgw.rb +7 -5
- data/lib/aspera/agent/node.rb +15 -7
- data/lib/aspera/agent/transferd.rb +167 -43
- data/lib/aspera/api/alee.rb +4 -1
- data/lib/aspera/api/aoc.rb +14 -11
- data/lib/aspera/api/ats.rb +4 -2
- data/lib/aspera/api/cos_node.rb +8 -5
- data/lib/aspera/api/faspex.rb +16 -9
- data/lib/aspera/api/httpgw.rb +9 -6
- data/lib/aspera/api/node.rb +23 -19
- data/lib/aspera/ascmd.rb +8 -5
- data/lib/aspera/ascp/installation.rb +84 -42
- data/lib/aspera/ascp/log.schema.yaml +1084 -0
- data/lib/aspera/ascp/log_analyzer/advice.rb +97 -0
- data/lib/aspera/ascp/log_analyzer/diagnostics.rb +344 -0
- data/lib/aspera/ascp/log_analyzer/lines.rb +75 -0
- data/lib/aspera/ascp/log_analyzer/log_file.rb +593 -0
- data/lib/aspera/ascp/log_analyzer/records.rb +379 -0
- data/lib/aspera/ascp/log_analyzer/rules.rb +172 -0
- data/lib/aspera/ascp/log_analyzer/session.rb +782 -0
- data/lib/aspera/ascp/log_analyzer.rb +354 -0
- data/lib/aspera/ascp/management.rb +102 -48
- data/lib/aspera/ascp/session_errors.rb +217 -0
- data/lib/aspera/assert.rb +4 -0
- data/lib/aspera/cli/ascp_actions.rb +16 -37
- data/lib/aspera/cli/ascp_logs_actions.rb +176 -0
- data/lib/aspera/cli/async_transfer_store.rb +7 -4
- data/lib/aspera/cli/bootstrapper.rb +37 -34
- data/lib/aspera/cli/command_line.rb +24 -6
- data/lib/aspera/cli/command_registry.rb +49 -4
- data/lib/aspera/cli/command_spec.rb +34 -4
- data/lib/aspera/cli/completion/ascli.bash +53 -5
- data/lib/aspera/cli/completion/ascli.fish +27 -8
- data/lib/aspera/cli/completion/ascli.ps1 +63 -0
- data/lib/aspera/cli/completion/ascli.zsh +36 -4
- data/lib/aspera/cli/completion_actions.rb +594 -0
- data/lib/aspera/cli/context.rb +9 -4
- data/lib/aspera/cli/deprecation.rb +5 -2
- data/lib/aspera/cli/error.rb +45 -0
- data/lib/aspera/cli/extended_value.rb +83 -24
- data/lib/aspera/cli/formatter.rb +142 -73
- data/lib/aspera/cli/gem_checker.rb +9 -6
- data/lib/aspera/cli/hints.rb +22 -11
- data/lib/aspera/cli/http.rb +17 -13
- data/lib/aspera/cli/info.rb +17 -6
- data/lib/aspera/cli/mailer.rb +7 -4
- data/lib/aspera/cli/mcp/http_servlet.rb +155 -0
- data/lib/aspera/cli/mcp/secrets.rb +146 -0
- data/lib/aspera/cli/mcp/tool.rb +232 -0
- data/lib/aspera/cli/option_declarator.rb +10 -4
- data/lib/aspera/cli/option_registry.rb +6 -3
- data/lib/aspera/cli/option_types.rb +17 -2
- data/lib/aspera/cli/option_value.rb +72 -11
- data/lib/aspera/cli/options.schema.yaml +856 -81
- data/lib/aspera/cli/parser.rb +64 -31
- data/lib/aspera/cli/plugins/alee.rb +7 -4
- data/lib/aspera/cli/plugins/aoc.rb +250 -44
- data/lib/aspera/cli/plugins/ats.rb +9 -8
- data/lib/aspera/cli/plugins/base.rb +51 -25
- data/lib/aspera/cli/plugins/basic_auth.rb +5 -2
- data/lib/aspera/cli/plugins/config.rb +207 -141
- data/lib/aspera/cli/plugins/console.rb +9 -4
- data/lib/aspera/cli/plugins/cos.rb +8 -4
- data/lib/aspera/cli/plugins/factory.rb +22 -8
- data/lib/aspera/cli/plugins/faspex5.rb +37 -44
- data/lib/aspera/cli/plugins/faspio.rb +41 -8
- data/lib/aspera/cli/plugins/httpgw.rb +8 -4
- data/lib/aspera/cli/plugins/mcp.rb +186 -121
- data/lib/aspera/cli/plugins/node.rb +41 -34
- data/lib/aspera/cli/plugins/oauth.rb +5 -1
- data/lib/aspera/cli/plugins/orchestrator.rb +572 -59
- data/lib/aspera/cli/plugins/preview.rb +69 -44
- data/lib/aspera/cli/plugins/server.rb +66 -12
- data/lib/aspera/cli/plugins/shares.rb +288 -48
- data/lib/aspera/cli/plugins/transferd.rb +223 -0
- data/lib/aspera/cli/preset_actions.rb +155 -33
- data/lib/aspera/cli/preset_manager.rb +72 -16
- data/lib/aspera/cli/prompt.rb +7 -2
- data/lib/aspera/cli/result.rb +28 -11
- data/lib/aspera/cli/runner.rb +193 -80
- data/lib/aspera/cli/secret_finder.rb +4 -1
- data/lib/aspera/cli/security.rb +204 -0
- data/lib/aspera/cli/special_values.rb +4 -1
- data/lib/aspera/cli/sync_actions.rb +13 -10
- data/lib/aspera/cli/table_fitter.rb +119 -0
- data/lib/aspera/cli/terminal_formatter.rb +32 -40
- data/lib/aspera/cli/transfer_actions.rb +11 -8
- data/lib/aspera/cli/transfer_agent.rb +31 -19
- data/lib/aspera/cli/transfer_progress.rb +13 -45
- data/lib/aspera/cli/vault_actions.rb +45 -0
- data/lib/aspera/cli/vault_manager.rb +197 -50
- data/lib/aspera/cli/version.rb +4 -1
- data/lib/aspera/cli/web_secret.html.erb +61 -0
- data/lib/aspera/cli/web_secret.rb +222 -0
- data/lib/aspera/cli/wizard.rb +58 -45
- data/lib/aspera/command_line_builder.rb +35 -5
- data/lib/aspera/command_line_converter.rb +4 -1
- data/lib/aspera/coverage.rb +103 -33
- data/lib/aspera/data_repository.rb +42 -25
- data/lib/aspera/dot_container.rb +4 -1
- data/lib/aspera/duration.rb +45 -0
- data/lib/aspera/environment.rb +106 -33
- data/lib/aspera/exec_spec.rb +9 -5
- data/lib/aspera/faspex_gw.rb +105 -35
- data/lib/aspera/faspex_postproc.rb +193 -47
- data/lib/aspera/formatter_interface.rb +4 -2
- data/lib/aspera/graphql.rb +5 -1
- data/lib/aspera/hash_ext.rb +3 -0
- data/lib/aspera/id_generator.rb +6 -3
- data/lib/aspera/json_rpc/client.rb +55 -35
- data/lib/aspera/json_rpc/version.rb +4 -0
- data/lib/aspera/line_logger.rb +4 -1
- data/lib/aspera/link_header.rb +4 -1
- data/lib/aspera/log.rb +20 -10
- data/lib/aspera/markdown.rb +155 -115
- data/lib/aspera/mime.rb +9 -0
- data/lib/aspera/nagios.rb +9 -5
- data/lib/aspera/node_emulator.rb +111 -112
- data/lib/aspera/oauth/client/base.rb +163 -0
- data/lib/aspera/oauth/{boot.rb → client/boot.rb} +8 -4
- data/lib/aspera/oauth/{factory.rb → client/factory.rb} +13 -3
- data/lib/aspera/oauth/{generic.rb → client/generic.rb} +5 -1
- data/lib/aspera/oauth/{json_credentials.rb → client/json_credentials.rb} +4 -1
- data/lib/aspera/oauth/{jwt.rb → client/jwt.rb} +6 -3
- data/lib/aspera/oauth/client/shares_web.rb +85 -0
- data/lib/aspera/oauth/{url_json.rb → client/url_json.rb} +4 -1
- data/lib/aspera/oauth/client/web.rb +84 -0
- data/lib/aspera/oauth/server/authorize.html.erb +34 -0
- data/lib/aspera/oauth/server/pkce.rb +427 -0
- data/lib/aspera/orchestrator_workflow_checker.rb +679 -0
- data/lib/aspera/persistency_action_once.rb +5 -3
- data/lib/aspera/persistency_folder.rb +6 -3
- data/lib/aspera/preview/file_types.rb +6 -3
- data/lib/aspera/preview/generator.rb +9 -5
- data/lib/aspera/preview/options.schema.yaml +3 -3
- data/lib/aspera/preview/terminal.rb +11 -6
- data/lib/aspera/preview/utils.rb +6 -4
- data/lib/aspera/products/connect.rb +5 -2
- data/lib/aspera/products/desktop.rb +4 -1
- data/lib/aspera/products/other.rb +4 -2
- data/lib/aspera/products/transferd.rb +6 -2
- data/lib/aspera/products/transferd_service.rb +610 -0
- data/lib/aspera/proxy_auto_config.js +2 -2
- data/lib/aspera/proxy_auto_config.rb +5 -2
- data/lib/aspera/rainbow.rb +30 -1
- data/lib/aspera/rest/aspera_errors.rb +55 -60
- data/lib/aspera/rest/call_error.rb +3 -0
- data/lib/aspera/rest/client.rb +42 -42
- data/lib/aspera/rest/error_analyzer.rb +14 -2
- data/lib/aspera/rest/list.rb +14 -10
- data/lib/aspera/rest/parameters.rb +3 -0
- data/lib/aspera/rest/util.rb +13 -4
- data/lib/aspera/rest.rb +9 -7
- data/lib/aspera/schema/IBM Aspera Faspex API-5.0-enhanced.yaml +9 -11
- data/lib/aspera/schema/IBM Aspera Orchestrator API-v1-enhanced.yaml +4089 -0
- data/lib/aspera/schema/IBM Aspera faspio Gateway API-1.0.0-enhanced.yaml +1097 -0
- data/lib/aspera/schema/IBM Aspera on Cloud API-0.2.6-enhanced.yaml +11 -11
- data/lib/aspera/schema/IBM Aspera on Cloud Automation API-1.0.5-enhanced.yaml +2437 -1437
- data/lib/aspera/schema/IBM_Aspera_Shares.yaml +819 -7
- data/lib/aspera/schema/async_tables.yaml +11 -10
- data/lib/aspera/schema/documentation.rb +56 -78
- data/lib/aspera/schema/reader.rb +46 -11
- data/lib/aspera/schema/registry.rb +45 -24
- data/lib/aspera/schema/transferd-config.schema.json +333 -0
- data/lib/aspera/schema/validator.rb +4 -1
- data/lib/aspera/sealed_hash.rb +166 -0
- data/lib/aspera/secret/hider.rb +201 -0
- data/lib/aspera/secret/reference.rb +150 -0
- data/lib/aspera/secret/resolver.rb +212 -0
- data/lib/aspera/secret/store/base.rb +153 -0
- data/lib/aspera/secret/store/encrypted_hash.rb +329 -0
- data/lib/aspera/secret/store/factory.rb +103 -0
- data/lib/aspera/secret/store/hashicorp_vault.rb +390 -0
- data/lib/aspera/secret/store/keeper.rb +141 -0
- data/lib/aspera/secret/store/macos_security.rb +284 -0
- data/lib/aspera/secret/store/one_password_api.rb +99 -0
- data/lib/aspera/secret/store/one_password_base.rb +42 -0
- data/lib/aspera/secret/store/one_password_cli.rb +110 -0
- data/lib/aspera/secret/store/secret_service.rb +125 -0
- data/lib/aspera/secret/strength.rb +119 -0
- data/lib/aspera/servlet_helpers.rb +114 -0
- data/lib/aspera/ssh.rb +10 -7
- data/lib/aspera/ssl.rb +5 -2
- data/lib/aspera/string_ext.rb +3 -0
- data/lib/aspera/sync/args.schema.yaml +6 -1
- data/lib/aspera/sync/conf.schema.yaml +25 -10
- data/lib/aspera/sync/database.rb +3 -0
- data/lib/aspera/sync/operations.rb +34 -12
- data/lib/aspera/temp_file_manager.rb +85 -22
- data/lib/aspera/timer_limiter.rb +3 -0
- data/lib/aspera/transfer/error.rb +4 -1
- data/lib/aspera/transfer/faux_file.rb +4 -1
- data/lib/aspera/transfer/parameters.rb +22 -14
- data/lib/aspera/transfer/result.rb +3 -0
- data/lib/aspera/transfer/resumer.rb +6 -4
- data/lib/aspera/transfer/spec.rb +45 -18
- data/lib/aspera/transfer/spec.schema.yaml +8 -5
- data/lib/aspera/transfer/units.rb +75 -0
- data/lib/aspera/uri_reader.rb +57 -7
- data/lib/aspera/web_auth/index.html.erb +20 -0
- data/lib/aspera/web_auth/paste.rb +109 -0
- data/lib/aspera/web_auth/receiver.rb +50 -0
- data/lib/aspera/web_auth/relay.rb +76 -0
- data/lib/aspera/web_auth/reply.html.erb +150 -0
- data/lib/aspera/web_auth/server.rb +59 -14
- data/lib/aspera/web_page.html.erb +262 -0
- data/lib/aspera/web_page.rb +66 -0
- data/lib/aspera/web_server_simple.rb +82 -13
- data/lib/aspera/yaml.rb +5 -1
- data/llms.txt +81 -0
- data/skills/ascli/SKILL.md +88 -0
- data.tar.gz.sig +0 -0
- metadata +116 -48
- metadata.gz.sig +0 -0
- data/lib/aspera/cli/mcp_tool.rb +0 -189
- data/lib/aspera/keychain/base.rb +0 -25
- data/lib/aspera/keychain/encrypted_hash.rb +0 -188
- data/lib/aspera/keychain/factory.rb +0 -59
- data/lib/aspera/keychain/hashicorp_vault.rb +0 -74
- data/lib/aspera/keychain/macos_security.rb +0 -171
- data/lib/aspera/keychain/one_password_api.rb +0 -86
- data/lib/aspera/keychain/one_password_base.rb +0 -34
- data/lib/aspera/keychain/one_password_cli.rb +0 -98
- data/lib/aspera/oauth/base.rb +0 -141
- data/lib/aspera/oauth/web.rb +0 -57
- data/lib/aspera/oauth.rb +0 -9
- data/lib/aspera/schema/IBM Aspera Orchestrator API-v1.yaml +0 -1784
- data/lib/aspera/schema/IBM Aspera faspio Gateway API-1.0.0.yaml +0 -249
- data/lib/aspera/secret_hider.rb +0 -117
- data/lib/aspera/web_auth/index.html +0 -147
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative '../assert'
|
|
7
|
+
require_relative '../log'
|
|
8
|
+
require_relative '../cli/prompt'
|
|
9
|
+
require_relative '../cli/info'
|
|
10
|
+
require_relative '../sealed_hash'
|
|
11
|
+
require_relative '../rainbow'
|
|
12
|
+
require 'uri'
|
|
13
|
+
using Rainbow
|
|
14
|
+
|
|
15
|
+
module Aspera
|
|
16
|
+
module WebAuth
|
|
17
|
+
# Receives the result of a web login from the user, who gives it in the terminal.
|
|
18
|
+
# No server is started: used when the browser cannot reach the loopback address of this host (e.g. SSH session, without tunnel).
|
|
19
|
+
# The user gives either:
|
|
20
|
+
# - a code (`SealedHash`) shown by the browser of the workstation, after `ascli config web_login <code>` (`ascli` is installed there)
|
|
21
|
+
# - the URL the browser was redirected to (it shows a connection error), or its query
|
|
22
|
+
# Same interface as `Server` for the part used by OAuth clients: `received_request`.
|
|
23
|
+
class Paste
|
|
24
|
+
class << self
|
|
25
|
+
# Extract the query parameters from what the user pasted
|
|
26
|
+
# @param input [String] Code, or full redirect URL, or the query only (with or without leading `?`)
|
|
27
|
+
# @return [Hash{String=>String}] Query parameters, includes a non-empty `state`
|
|
28
|
+
# @raise [ParameterError] if the input has no query, or no `state`
|
|
29
|
+
def parse(input)
|
|
30
|
+
text = input.to_s.strip
|
|
31
|
+
raise ParameterError, 'Nothing was pasted' if text.empty?
|
|
32
|
+
params =
|
|
33
|
+
if SealedHash.sealed?(text)
|
|
34
|
+
data = SealedHash.unseal(text, base_key: Cli::Info::CMD_NAME)
|
|
35
|
+
raise ParameterError, 'This code is for ascli on the workstation: paste the code shown by the browser after login' if data.key?('login_url')
|
|
36
|
+
data
|
|
37
|
+
else
|
|
38
|
+
parse_query(text)
|
|
39
|
+
end
|
|
40
|
+
raise ParameterError, 'No "state" found in what was pasted' if params['state'].to_s.empty?
|
|
41
|
+
params
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
# @param text [String] Full redirect URL, or query
|
|
47
|
+
# @return [Hash{String=>String}]
|
|
48
|
+
def parse_query(text)
|
|
49
|
+
# fragment is not sent to a server, ignore it
|
|
50
|
+
text = text.sub(/#.*\z/m, '')
|
|
51
|
+
query =
|
|
52
|
+
if text.match?(%r{\A[a-z][a-z0-9+.-]*://}i)
|
|
53
|
+
URI.parse(text).query.to_s
|
|
54
|
+
else
|
|
55
|
+
text.delete_prefix('?')
|
|
56
|
+
end
|
|
57
|
+
raise ParameterError, 'No query found in pasted URL: copy the full URL from the address bar of the browser' if query.empty?
|
|
58
|
+
URI.decode_www_form(query).to_h
|
|
59
|
+
rescue URI::InvalidURIError, ArgumentError => e
|
|
60
|
+
raise ParameterError, "Pasted text is not a valid code, URL or query: #{e.message}"
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# @param redirect_uri [String] Loopback URL registered for the login (the browser fails to connect to it)
|
|
65
|
+
# @param login_url [String, nil] URL of the login page: if set, a code is given to the user for `ascli` on the workstation
|
|
66
|
+
# @param reply_keys [Array, nil] Keys of the query needed to continue (with `login_url`)
|
|
67
|
+
def initialize(redirect_uri, login_url: nil, reply_keys: nil)
|
|
68
|
+
@redirect_uri = redirect_uri
|
|
69
|
+
@login_url = login_url
|
|
70
|
+
@reply_keys = reply_keys
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# @return [Boolean] true if the message given to the user contains the login URL (so it shall not be displayed separately)
|
|
74
|
+
def shows_login_url?
|
|
75
|
+
!@login_url.nil?
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Ask the user for the code, or the URL the browser was redirected to
|
|
79
|
+
# Input is not echoed on a terminal: it contains an authorization code or tokens.
|
|
80
|
+
# @return [Hash{String=>String}] The query
|
|
81
|
+
def received_request
|
|
82
|
+
Log.log.warn do
|
|
83
|
+
browser_steps = [
|
|
84
|
+
"The browser shows a connection error on #{@redirect_uri}: this is expected.",
|
|
85
|
+
'Copy the full URL from the address bar of the browser, and paste it in the prompt below.'
|
|
86
|
+
]
|
|
87
|
+
if @login_url.nil?
|
|
88
|
+
(['USER ACTION: Log in with the web browser, then:'] + browser_steps.map { |s| " - #{s}" }).join("\n")
|
|
89
|
+
else
|
|
90
|
+
code = SealedHash.seal({'login_url' => @login_url.to_s, 'redirect_uri' => @redirect_uri, 'reply_keys' => @reply_keys}, base_key: Cli::Info::CMD_NAME)
|
|
91
|
+
[
|
|
92
|
+
'USER ACTION: To continue, choose one of these two ways:',
|
|
93
|
+
" 1. With any browser (#{Cli::Info::CMD_NAME} is not needed on the workstation):",
|
|
94
|
+
' - Open this URL in a browser and log in:',
|
|
95
|
+
" #{@login_url.to_s.red}",
|
|
96
|
+
*browser_steps.map { |s| " - #{s}" },
|
|
97
|
+
" 2. If #{Cli::Info::CMD_NAME} is installed on the workstation that has the browser:",
|
|
98
|
+
' - Run there:',
|
|
99
|
+
" #{Cli::Info::CMD_NAME} config web_login #{code}",
|
|
100
|
+
' - Log in in the page that opens.',
|
|
101
|
+
' - Copy the code shown by the browser, and paste it in the prompt below.'
|
|
102
|
+
].join("\n")
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
self.class.parse(Cli::Prompt.prompt_user_input('Code or URL', sensitive: true))
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative 'server'
|
|
7
|
+
require_relative 'paste'
|
|
8
|
+
require_relative '../environment'
|
|
9
|
+
require_relative '../log'
|
|
10
|
+
|
|
11
|
+
module Aspera
|
|
12
|
+
module WebAuth
|
|
13
|
+
class << self
|
|
14
|
+
# Create the object that receives the result of a web login, according to `Environment#web_auth` (option `ui.web_auth`):
|
|
15
|
+
# `:port` listens on the loopback address of `redirect_uri`, `:paste` asks the user to give the result in the terminal.
|
|
16
|
+
# Both provide `received_request`.
|
|
17
|
+
# @param redirect_uri [String] Loopback URL that receives the result
|
|
18
|
+
# @param additional_info [String] Information in web page (only with `:port`)
|
|
19
|
+
# @param login_url [String, URI] URL of the login page: with `:paste`, a code for `ascli` on the workstation is given to the user,
|
|
20
|
+
# unless the browser is started by `ascli` (the user has no time to use the code, and the browser is local)
|
|
21
|
+
# @param reply_keys [Array<String>] Keys of the query that the client needs (with `login_url`)
|
|
22
|
+
# @return [Server, Paste]
|
|
23
|
+
def receiver(redirect_uri, additional_info = nil, login_url: nil, reply_keys: nil)
|
|
24
|
+
env = Environment.instance
|
|
25
|
+
case env.web_auth
|
|
26
|
+
when :paste
|
|
27
|
+
login_url = nil if env.browser_command || env.url_method.eql?(:graphical)
|
|
28
|
+
Paste.new(redirect_uri, login_url: login_url, reply_keys: reply_keys)
|
|
29
|
+
when :port
|
|
30
|
+
if env.url_method.eql?(:text) && env.browser_command.nil? && (ENV.key?('SSH_CONNECTION') || ENV.key?('SSH_TTY'))
|
|
31
|
+
Log.log.warn do
|
|
32
|
+
"Web login: the browser must reach port #{URI.parse(redirect_uri).port} of this host (SSH tunnel). " \
|
|
33
|
+
'If not possible, use option --ui.web_auth=paste'
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
Server.new(redirect_uri, additional_info)
|
|
37
|
+
else Aspera.error_unexpected_value(env.web_auth) { 'ui.web_auth' }
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Let the user open the login page, unless the receiver already gives the URL in its own message
|
|
42
|
+
# @param login_receiver [Server, Paste] Result of `receiver`
|
|
43
|
+
# @param login_url [String, URI] URL of the login page
|
|
44
|
+
def open_login_page(login_receiver, login_url)
|
|
45
|
+
return if login_receiver.is_a?(Paste) && login_receiver.shows_login_url?
|
|
46
|
+
Environment.instance.open_uri(login_url)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative 'server'
|
|
7
|
+
require_relative '../web_server_simple'
|
|
8
|
+
require_relative '../environment'
|
|
9
|
+
require_relative '../assert'
|
|
10
|
+
require 'uri'
|
|
11
|
+
|
|
12
|
+
module Aspera
|
|
13
|
+
module WebAuth
|
|
14
|
+
# Login on the workstation that has the browser, for `ascli` that runs on another host (option `ui.web_auth=paste`).
|
|
15
|
+
# The remote `ascli` gives a code (`SealedHash`) with the URL of the login page, the loopback URL to which the browser is redirected,
|
|
16
|
+
# and the keys of the reply. Here, a local server receives the redirection, and the page shown in the browser gives a code (type reply)
|
|
17
|
+
# to paste in the terminal of the remote `ascli`.
|
|
18
|
+
module Relay
|
|
19
|
+
# @!attribute [r] login_url
|
|
20
|
+
# @return [URI] URL of the login page (https)
|
|
21
|
+
# @!attribute [r] redirect_uri
|
|
22
|
+
# @return [String] Loopback URL to which the browser is redirected
|
|
23
|
+
# @!attribute [r] reply_keys
|
|
24
|
+
# @return [Array<String>] Keys of the query that are given to the remote `ascli`
|
|
25
|
+
# @!attribute [r] host
|
|
26
|
+
# @return [String] Host of the login page, calculated here (not given by the remote `ascli`)
|
|
27
|
+
Login = Struct.new(:login_url, :redirect_uri, :reply_keys, :host, keyword_init: true)
|
|
28
|
+
# Keys of the reply are names of query parameters
|
|
29
|
+
REPLY_KEY_REGEX = /\A[a-z][a-z0-9_]{0,63}\z/
|
|
30
|
+
MAX_REPLY_KEYS = 16
|
|
31
|
+
private_constant :REPLY_KEY_REGEX, :MAX_REPLY_KEYS
|
|
32
|
+
|
|
33
|
+
class << self
|
|
34
|
+
# The code comes from another host, or from a message: its content is checked.
|
|
35
|
+
# @param data [Hash] Content of a code of type login: `login_url`, `redirect_uri`, `reply_keys`
|
|
36
|
+
# @return [Login]
|
|
37
|
+
# @raise [ParameterError] if content is not acceptable
|
|
38
|
+
def parse(data)
|
|
39
|
+
Aspera.assert_type(data, Hash, type: ParameterError) { 'login code' }
|
|
40
|
+
login_url = parse_uri(data['login_url'], 'login_url')
|
|
41
|
+
raise ParameterError, "URL of the login page shall be https: #{login_url.scheme}://#{login_url.host}" unless login_url.scheme.eql?('https')
|
|
42
|
+
raise ParameterError, 'URL of the login page has no host' if login_url.host.to_s.empty?
|
|
43
|
+
redirect = parse_uri(data['redirect_uri'], 'redirect_uri')
|
|
44
|
+
raise ParameterError, "redirect_uri shall be http or https, with a port: #{redirect}" unless %w[http https].include?(redirect.scheme) && redirect.port
|
|
45
|
+
raise ParameterError, "redirect_uri host shall be loopback (localhost, 127.0.0.0/8, ::1): #{redirect.host}" unless WebServerSimple.loopback?(redirect.hostname.to_s)
|
|
46
|
+
keys = data['reply_keys']
|
|
47
|
+
valid_keys = keys.is_a?(Array) && !keys.empty? && keys.length <= MAX_REPLY_KEYS && keys.all? { |key| key.is_a?(String) && key.match?(REPLY_KEY_REGEX) }
|
|
48
|
+
raise ParameterError, 'reply_keys shall be a list of parameter names' unless valid_keys
|
|
49
|
+
Login.new(login_url: login_url, redirect_uri: redirect.to_s, reply_keys: keys, host: login_url.host.downcase)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Open the login page, receive the redirection, and show the code to the user in the browser.
|
|
53
|
+
# @param login [Login] Result of `parse`
|
|
54
|
+
# @return [nil]
|
|
55
|
+
def run(login)
|
|
56
|
+
server = Server.new(login.redirect_uri, "#{login.host} - login for ascli on another host", reply_keys: login.reply_keys)
|
|
57
|
+
Environment.instance.open_uri(login.login_url)
|
|
58
|
+
server.received_request
|
|
59
|
+
# the page that gives the code is sent after the request is received: wait for it before ending
|
|
60
|
+
server.wait_stopped
|
|
61
|
+
nil
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
private
|
|
65
|
+
|
|
66
|
+
# @return [URI]
|
|
67
|
+
def parse_uri(value, name)
|
|
68
|
+
raise ParameterError, "#{name} is missing" unless value.is_a?(String) && !value.empty?
|
|
69
|
+
URI.parse(value)
|
|
70
|
+
rescue URI::InvalidURIError => e
|
|
71
|
+
raise ParameterError, "#{name} is not a valid URL: #{e.message}"
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
<%# Content of the page displayed after login when the reply is given to the user, to paste in the terminal of ascli, in layout of Aspera::WebPage. Variables: additional_info, code, nonce %>
|
|
2
|
+
<style>
|
|
3
|
+
.code-box {
|
|
4
|
+
display: flex;
|
|
5
|
+
align-items: stretch;
|
|
6
|
+
gap: 0.5rem;
|
|
7
|
+
margin-top: 1.25rem;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.code {
|
|
11
|
+
flex: 1;
|
|
12
|
+
min-width: 0;
|
|
13
|
+
padding: 0.6rem 0.75rem;
|
|
14
|
+
text-align: left;
|
|
15
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
|
16
|
+
font-size: 0.8rem;
|
|
17
|
+
line-height: 1.4;
|
|
18
|
+
letter-spacing: 0.05em;
|
|
19
|
+
word-break: break-all;
|
|
20
|
+
max-height: 9rem;
|
|
21
|
+
overflow-y: auto;
|
|
22
|
+
background: var(--surface);
|
|
23
|
+
color: var(--text);
|
|
24
|
+
border: 1px solid var(--border);
|
|
25
|
+
border-radius: 6px;
|
|
26
|
+
user-select: none;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.code.revealed {
|
|
30
|
+
user-select: all;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.code-box button.icon {
|
|
34
|
+
flex: none;
|
|
35
|
+
width: 2.75rem;
|
|
36
|
+
padding: 0;
|
|
37
|
+
display: flex;
|
|
38
|
+
align-items: center;
|
|
39
|
+
justify-content: center;
|
|
40
|
+
background: var(--card-bg);
|
|
41
|
+
color: var(--text-secondary);
|
|
42
|
+
border: 1px solid var(--input-border);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.code-box button.icon:hover {
|
|
46
|
+
color: var(--accent);
|
|
47
|
+
border-color: var(--accent);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.code-box button.icon svg.hide,
|
|
51
|
+
.code-box button.icon.on svg.show {
|
|
52
|
+
display: none;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.code-box button.icon.on svg.hide {
|
|
56
|
+
display: block;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.status {
|
|
60
|
+
min-height: 1.4rem;
|
|
61
|
+
font-size: 0.85rem;
|
|
62
|
+
color: var(--success);
|
|
63
|
+
}
|
|
64
|
+
</style>
|
|
65
|
+
|
|
66
|
+
<div class="icon-circle ok">
|
|
67
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" viewBox="0 0 32 32" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round">
|
|
68
|
+
<polyline points="6 16 13 23 26 9"/>
|
|
69
|
+
</svg>
|
|
70
|
+
</div>
|
|
71
|
+
|
|
72
|
+
<h1>Login Complete</h1>
|
|
73
|
+
<p>Copy this code, and paste it in the terminal where <b>ascli</b> waits for it. You can then close this window.</p>
|
|
74
|
+
|
|
75
|
+
<% unless additional_info.to_s.empty? %>
|
|
76
|
+
<div class="info-box">
|
|
77
|
+
<%= h additional_info %>
|
|
78
|
+
</div>
|
|
79
|
+
<% end %>
|
|
80
|
+
|
|
81
|
+
<div class="code-box">
|
|
82
|
+
<div id="code" class="code" aria-live="polite">••••••••••••••••••••</div>
|
|
83
|
+
<button type="button" id="reveal" class="icon" title="Show the code" aria-label="Show the code" aria-pressed="false">
|
|
84
|
+
<svg class="show" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
85
|
+
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/>
|
|
86
|
+
<circle cx="12" cy="12" r="3"/>
|
|
87
|
+
</svg>
|
|
88
|
+
<svg class="hide" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
89
|
+
<path d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"/>
|
|
90
|
+
<line x1="1" y1="1" x2="23" y2="23"/>
|
|
91
|
+
</svg>
|
|
92
|
+
</button>
|
|
93
|
+
</div>
|
|
94
|
+
<div class="actions">
|
|
95
|
+
<button type="button" id="copy" class="allow">Copy</button>
|
|
96
|
+
</div>
|
|
97
|
+
<p id="status" class="status" role="status"></p>
|
|
98
|
+
|
|
99
|
+
<%# The code is in this script only, not in the page: it is inserted in the page when the user shows it %>
|
|
100
|
+
<script nonce="<%= h nonce %>">
|
|
101
|
+
(function () {
|
|
102
|
+
var code = <%= JSON.generate(code.to_s).gsub('<', '\u003c') %>;
|
|
103
|
+
var box = document.getElementById('code');
|
|
104
|
+
var mask = box.textContent;
|
|
105
|
+
var reveal = document.getElementById('reveal');
|
|
106
|
+
var status = document.getElementById('status');
|
|
107
|
+
var shown = false;
|
|
108
|
+
|
|
109
|
+
reveal.addEventListener('click', function () {
|
|
110
|
+
shown = !shown;
|
|
111
|
+
box.textContent = shown ? code : mask;
|
|
112
|
+
box.classList.toggle('revealed', shown);
|
|
113
|
+
reveal.classList.toggle('on', shown);
|
|
114
|
+
reveal.setAttribute('aria-pressed', shown ? 'true' : 'false');
|
|
115
|
+
var label = shown ? 'Hide the code' : 'Show the code';
|
|
116
|
+
reveal.title = label;
|
|
117
|
+
reveal.setAttribute('aria-label', label);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
function legacyCopy() {
|
|
121
|
+
var area = document.createElement('textarea');
|
|
122
|
+
area.value = code;
|
|
123
|
+
area.setAttribute('readonly', '');
|
|
124
|
+
area.style.position = 'fixed';
|
|
125
|
+
area.style.opacity = '0';
|
|
126
|
+
document.body.appendChild(area);
|
|
127
|
+
area.select();
|
|
128
|
+
var ok = false;
|
|
129
|
+
try { ok = document.execCommand('copy'); } catch (e) { ok = false; }
|
|
130
|
+
document.body.removeChild(area);
|
|
131
|
+
return ok;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function done(ok) {
|
|
135
|
+
status.style.color = ok ? '' : 'var(--danger)';
|
|
136
|
+
status.textContent = ok ? 'Copied. Paste it in the terminal.' : 'Copy failed: show the code, select it and copy it.';
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
document.getElementById('copy').addEventListener('click', function () {
|
|
140
|
+
if (navigator.clipboard && window.isSecureContext) {
|
|
141
|
+
navigator.clipboard.writeText(code).then(function () { done(true); }, function () { done(legacyCopy()); });
|
|
142
|
+
} else {
|
|
143
|
+
done(legacyCopy());
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// The callback URL contains a code or tokens: remove the query from the address bar and from the entry of the session history
|
|
148
|
+
if (window.history && history.replaceState) history.replaceState(null, '', location.pathname);
|
|
149
|
+
})();
|
|
150
|
+
</script>
|
|
@@ -1,13 +1,31 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative '../web_server_simple'
|
|
7
|
+
require_relative '../servlet_helpers'
|
|
8
|
+
require_relative '../web_page'
|
|
9
|
+
require_relative '../sealed_hash'
|
|
10
|
+
require_relative '../cli/info'
|
|
11
|
+
require_relative '../assert'
|
|
12
|
+
require 'json'
|
|
13
|
+
require 'securerandom'
|
|
6
14
|
|
|
7
15
|
module Aspera
|
|
8
16
|
module WebAuth
|
|
9
17
|
# servlet called on callback: it records the callback request
|
|
10
18
|
class Servlet < WEBrick::HTTPServlet::AbstractServlet
|
|
19
|
+
include ServletHelpers
|
|
20
|
+
|
|
21
|
+
# ERB template of page displayed in browser after authentication
|
|
22
|
+
HTML_TEMPLATE_PATH = File.join(__dir__, 'index.html.erb')
|
|
23
|
+
# ERB template of page displayed in browser after authentication, when the reply is given to the user to paste in a terminal
|
|
24
|
+
REPLY_TEMPLATE_PATH = File.join(__dir__, 'reply.html.erb')
|
|
25
|
+
# Policy of the reply page: it has a secret. Only its own script (with nonce) and style, nothing external
|
|
26
|
+
REPLY_CSP = "default-src 'none'; img-src data:; style-src 'unsafe-inline'; script-src 'nonce-%<nonce>s'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'"
|
|
27
|
+
private_constant :HTML_TEMPLATE_PATH, :REPLY_TEMPLATE_PATH, :REPLY_CSP
|
|
28
|
+
|
|
11
29
|
# @param server [WEBrick::HTTPServer] the HTTP server instance
|
|
12
30
|
# @param web_auth [Server] the Server instance to record the callback
|
|
13
31
|
def initialize(server, web_auth)
|
|
@@ -20,39 +38,66 @@ module Aspera
|
|
|
20
38
|
|
|
21
39
|
def service(request, response)
|
|
22
40
|
Log.log.debug { "received request from browser #{request.request_method} #{request.path}" }
|
|
23
|
-
|
|
24
|
-
|
|
41
|
+
# Refuse requests of other web pages
|
|
42
|
+
check_request(request)
|
|
43
|
+
Aspera.assert_values(request.request_method, ['GET'], type: WEBrick::HTTPStatus::MethodNotAllowed) { "Unsupported method: #{request.request_method}" }
|
|
44
|
+
Aspera.assert_values(request.path, [@web_auth.expected_path], type: WEBrick::HTTPStatus::NotFound) { "Unsupported path: #{request.path}" }
|
|
25
45
|
# response to browser
|
|
26
46
|
response.status = 200
|
|
27
|
-
|
|
28
|
-
|
|
47
|
+
if @web_auth.reply_keys.nil?
|
|
48
|
+
WebPage.secure_headers(response)
|
|
49
|
+
response.body = WebPage.render(HTML_TEMPLATE_PATH, title: 'Authentication Complete', additional_info: @web_auth.additional_info)
|
|
50
|
+
else
|
|
51
|
+
render_reply(request, response)
|
|
52
|
+
end
|
|
29
53
|
# continue internal processing
|
|
30
54
|
@web_auth.signal_request(request)
|
|
31
55
|
nil
|
|
32
56
|
end
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
|
|
60
|
+
# Page that gives the reply to the user: the code to paste in the terminal of the remote ascli
|
|
61
|
+
def render_reply(request, response)
|
|
62
|
+
nonce = SecureRandom.base64(16)
|
|
63
|
+
WebPage.secure_headers(response, content_security_policy: format(REPLY_CSP, nonce: nonce))
|
|
64
|
+
code = SealedHash.seal(request.query.slice(*@web_auth.reply_keys).transform_values(&:to_s), base_key: Cli::Info::CMD_NAME)
|
|
65
|
+
response.body = WebPage.render(REPLY_TEMPLATE_PATH, title: 'Login Complete', additional_info: @web_auth.additional_info, code: code, nonce: nonce)
|
|
66
|
+
end
|
|
33
67
|
end
|
|
34
68
|
|
|
35
69
|
# start a local web server
|
|
36
70
|
# then start a browser that will callback the local server upon authentication
|
|
37
71
|
# store the final query
|
|
38
72
|
class Server < WebServerSimple
|
|
39
|
-
|
|
73
|
+
# @return [Array<String>, nil] Keys of the query that the page gives to the user as a code to paste in a terminal, `nil` for the standard page
|
|
74
|
+
attr_reader :additional_info, :expected_path, :reply_keys
|
|
40
75
|
|
|
41
76
|
# @param endpoint_url [String] e.g. 'https://127.0.0.1:12345'
|
|
42
77
|
# @param additional_info [String] Information in web page
|
|
43
|
-
|
|
78
|
+
# @param reply_keys [Array<String>, nil] If set, the page shows to the user a code with these keys of the query, to paste in the terminal of `ascli` that waits for it
|
|
79
|
+
def initialize(endpoint_url, additional_info = nil, reply_keys: nil)
|
|
44
80
|
uri = URI.parse(endpoint_url)
|
|
45
81
|
super(uri)
|
|
82
|
+
@reply_keys = reply_keys
|
|
46
83
|
@mutex = Mutex.new
|
|
47
84
|
@cond = ConditionVariable.new
|
|
48
85
|
@expected_path = uri.path.empty? ? '/' : uri.path
|
|
49
86
|
@query = nil
|
|
50
|
-
@
|
|
51
|
-
@info_html = "<p>#{ERB::Util.html_escape(@info_html)}</p>" unless @info_html.empty?
|
|
87
|
+
@additional_info = additional_info
|
|
52
88
|
# last argument (self) is provided to constructor of servlet
|
|
53
89
|
mount(@expected_path, Servlet, self)
|
|
54
90
|
# server runs in thread
|
|
55
|
-
Thread.new { start }
|
|
91
|
+
@thread = Thread.new { start }
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Wait until the server thread has ended: the response of the last request (page shown to the user) is sent.
|
|
95
|
+
# To call after `received_request`, when the process does not continue with a long operation.
|
|
96
|
+
# @param timeout [Integer] Maximum time to wait, in seconds
|
|
97
|
+
# @return [nil]
|
|
98
|
+
def wait_stopped(timeout = 10)
|
|
99
|
+
@thread.join(timeout)
|
|
100
|
+
nil
|
|
56
101
|
end
|
|
57
102
|
|
|
58
103
|
# Called by web server thread on received request
|
|
@@ -70,8 +115,8 @@ module Aspera
|
|
|
70
115
|
# wait for request on web server (main thread)
|
|
71
116
|
# @return [Hash] the query
|
|
72
117
|
def received_request
|
|
73
|
-
# wait for signal from thread
|
|
74
|
-
@mutex.synchronize { @cond.wait(@mutex) }
|
|
118
|
+
# wait for signal from thread, unless the request was already received (signal is not memorized)
|
|
119
|
+
@mutex.synchronize { @cond.wait(@mutex) while @query.nil? }
|
|
75
120
|
# tell server thread to stop
|
|
76
121
|
shutdown
|
|
77
122
|
return @query
|