Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix authentication issues with code-server #2

Merged
merged 16 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/tmp/
/local/
/code-server*/
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

22 changes: 0 additions & 22 deletions LICENSE.txt

This file was deleted.

10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ use and place this wherever you store batch connect apps (`/var/www/ood/apps/sys

```sh
# replace URL with latest release from code-server
wget https://github.com/cdr/code-server/releases/download/2.1692-vsc1.39.2/code-server2.1692-vsc1.39.2-linux-x86_64.tar.gz
tar -xzf code-server2.1692-vsc1.39.2-linux-x86_64.tar.gz
wget https://github.com/cdr/code-server/releases/download/3.2.0/code-server-3.2.0-linux-x86_64.tar.gz
tar -xzf code-server-3.2.0-linux-x86_64.tar.gz
```

3. You will notice code-server is an executable inside that directory and can get the full path:

```sh
$ readlink -f code-server2.1692-vsc1.39.2-linux-x86_64/code-server
/users/PZS0562/efranz/code-server2.1692-vsc1.39.2-linux-x86_64/code-server
$ readlink -f code-server-3.2.0-linux-x86_64.tar.gz
/users/PZS0562/efranz/code-server-3.2.0-linux-x86_64.tar.gz
```

4. Update the path to the code-server binary in the script https://github.com/OSC/bc_osc_codeserver/blob/3082790ee69c82fe6fe757074da7d8d18c7d7e3d/template/script.sh.erb#L27:

```diff
# An arbitrary path...
- /fs/project/PZS0714/mrodgers/bin/code-server-2.1523-vsc1.38.1 \
+ /users/PZS0562/efranz/code-server2.1692-vsc1.39.2-linux-x86_64/code-server \
+ /users/PZS0562/efranz/code-server-3.2.0-linux-x86_64/code-server \
--auth=password \
--port="$port" \
```
Expand Down
Binary file added code-server-3.4.1-linux-amd64.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion form.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ attributes:
data-filepicker: true
data-target-file-type: dirs # Valid values are: files, dirs, or both
readonly: false
help: "Select your project directory; defaults to $HOME"
help: "Select your project directory; defaults to $HOME"
Binary file modified icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion submit.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ batch_connect:
script:
native:
resources:
nodes: "1:ppn=1:owens"
nodes: "1:ppn=2:owens"
10 changes: 6 additions & 4 deletions template/after.sh.erb
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
9 changes: 6 additions & 3 deletions template/before.sh.erb
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)"
51 changes: 33 additions & 18 deletions template/script.sh.erb
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)
msquee marked this conversation as resolved.
Show resolved Hide resolved

# 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 %>"
30 changes: 27 additions & 3 deletions view.html.erb
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 %>">
<%
msquee marked this conversation as resolved.
Show resolved Hide resolved
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>