-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from OSC/upgrade/codeserver
Fix authentication issues with code-server
- Loading branch information
Showing
12 changed files
with
754 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/tmp/ | ||
/local/ | ||
/code-server*/ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ batch_connect: | |
script: | ||
native: | ||
resources: | ||
nodes: "1:ppn=1:owens" | ||
nodes: "1:ppn=2:owens" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
# Wait for the Jupyter server to start | ||
echo "Waiting for Jupyter server to open port ${port}..." | ||
# Wait for the Code Server to start | ||
echo "$(date): Waiting for Code Server to open port ${port}..." | ||
|
||
if wait_until_port_used "${host}:${port}" 600; then | ||
echo "Discovered code-server listening on port ${port}!" | ||
echo "$(date): Discovered code-server listening on port ${port}!" | ||
else | ||
echo "Timed out waiting for Jupyter server to open port ${port}!" | ||
echo "$(date): Timed out waiting for Code Server to open port ${port}!" | ||
clean_up 1 | ||
fi | ||
|
||
sleep 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
# # Export the module function if it exists | ||
# Export the module function if it exists | ||
[[ $(type -t module) == "function" ]] && export -f module | ||
|
||
# # Find available port to run server on | ||
# Find available port to run server on | ||
export port=$(find_port ${host}) | ||
|
||
# # Generate SHA1 encrypted password (requires OpenSSL installed) | ||
# Export compute node the script is running on | ||
export host="${host}" | ||
|
||
# Generate SHA1 encrypted password (requires OpenSSL installed) | ||
export password="$(create_passwd 16)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,53 @@ | ||
#!/usr/bin/env bash | ||
<%- | ||
# Ensure that code-server always starts up in either a user defined directory or the home directory | ||
working_dir = Pathname.new(context.working_dir) | ||
if ! working_dir.exist? || working_dir.to_s.empty? | ||
working_dir = Pathname.new(ENV['HOME']) | ||
elsif working_dir.file? | ||
working_dir = working_dir.parent | ||
end | ||
<% | ||
# Determine the application root from session token. | ||
app_root = BatchConnect::App.from_token(session.token).root.realpath | ||
|
||
# Set our working directory. | ||
working_dir = Pathname.new(context.working_dir) | ||
|
||
# Ensure that code-server always starts up in either a user defined directory or the home directory. | ||
if ! working_dir.exist? | ||
working_dir = Pathname.new(ENV['HOME']) | ||
elsif working_dir.file? | ||
working_dir = working_dir.parent | ||
end | ||
%> | ||
|
||
# Setup environment | ||
CODE_SERVER="${CODE_SERVER:-/users/PZS0562/efranz/code-server2.1692-vsc1.39.2-linux-x86_64/code-server}" | ||
# Setup environment. | ||
APP_ROOT="<%= app_root.to_s %>" | ||
CODE_SERVER_DATAROOT="$HOME/.local/share/bc_osc_codeserver" | ||
|
||
# Path to Code Server binary. /code-server/ is expected to be a symlink to #{CODE_SERVER_FOLDER}/bin/code-server | ||
# | ||
# ln -s code-server-3.3.1-linux-x86_64 code-server | ||
CODE_SERVER="${CODE_SERVER:-${APP_ROOT}/code-server/bin/code-server}" | ||
|
||
# Ensure a dataroot for Code Server | ||
# Ensure a dataroot for Code Server. | ||
mkdir -p "$CODE_SERVER_DATAROOT/extensions" | ||
|
||
# Expose the password to the server | ||
# Expose the password to the server. | ||
export PASSWORD="$password" | ||
|
||
# VSCode complains that system git is too old | ||
# Print compute node. | ||
echo "$(date): Running on compute node ${compute_node}:$port" | ||
|
||
# VSCode complains that system git is too old. | ||
module load git | ||
|
||
echo "" | ||
|
||
# | ||
# Start Code Server | ||
# Start Code Server. | ||
# | ||
echo $CODE_SERVER | ||
echo "$(date): Started code-server" | ||
echo "" | ||
|
||
# An arbitrary path... | ||
$CODE_SERVER \ | ||
--auth=password \ | ||
--port="$port" \ | ||
--auth="password" \ | ||
--bind-addr="0.0.0.0:${port}" \ | ||
--disable-telemetry \ | ||
--extra-extensions-dir="$CODE_SERVER_DATAROOT/extensions" \ | ||
--user-data-dir="$CODE_SERVER_DATAROOT" \ | ||
--log debug \ | ||
"<%= working_dir.to_s %>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,30 @@ | ||
<form action="/rnode/<%= host %>/<%= port %>/login" method="post" target="_blank"> | ||
<input type="hidden" name="password" value="<%= password %>"> | ||
<% | ||
require 'digest' | ||
|
||
# Generate form id, based on host and port | ||
form_id = Digest::SHA1.hexdigest("--" + host.to_s + "--" + port.to_s + "--") | ||
|
||
# Generate SHA256 digest of Code Server Password | ||
cookieValue = Digest::SHA256.hexdigest(password) | ||
%> | ||
|
||
<script type="text/javascript"> | ||
(function () { | ||
let date = new Date() | ||
date.setTime(date.getTime() + (7*24*60*60*1000)) | ||
let expires = "expires=" + date.toUTCString() | ||
let cookiePath = "path=/rnode/" + "<%= host.to_s %>" + "/" + "<%= port.to_s %>/"; | ||
/** | ||
We have to use "key" as the cookie name since upstream in cdr/code-server | ||
the authentication cookie is hard coded "key" | ||
*/ | ||
let cookie = `key=<%= cookieValue %>;${expires};${cookiePath};secure`; | ||
document.cookie = cookie; | ||
})(); | ||
</script> | ||
|
||
<form id="<%= form_id %>" action="/rnode/<%= host %>/<%= port %>/" method="get" target="_blank"> | ||
<button class="btn btn-primary" type="submit"> | ||
<i class="fa fa-cogs"></i> Connect to Code Server | ||
<i class="fa fa-cogs"></i> Connect to VS Code | ||
</button> | ||
</form> |