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

Enable home dir persistence, fix sudo error, fix home dir permissions, optimize nix config #1

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
38 changes: 0 additions & 38 deletions .devcontainer/devcontainer.json

This file was deleted.

50 changes: 5 additions & 45 deletions .idx/dev.nix
Original file line number Diff line number Diff line change
@@ -1,56 +1,16 @@
# To learn more about how to use Nix to configure your environment
# see: https://developers.google.com/idx/guides/customize-idx-env
{ pkgs, ... }: {
# Which nixpkgs channel to use.
channel = "stable-23.11"; # or "unstable"
# Use https://search.nixos.org/packages to find packages
packages = [
pkgs.sudo
pkgs.openssh
pkgs.busybox
# pkgs.go
# pkgs.python311
# pkgs.python311Packages.pip
# pkgs.nodejs_20
# pkgs.nodePackages.nodemon
];
# Sets environment variables in the workspace
channel = "stable-23.11";
packages = [];
env = {};
services.docker.enable = true;
idx = {
# Search for the extensions you want on https://open-vsx.org/ and use "publisher.id"
extensions = [
# "vscodevim.vim"
];
# Enable previews
previews = {
enable = true;
previews = {
# web = {
# # Example: run "npm run dev" with PORT set to IDX's defined port for previews,
# # and show it in IDX's web preview panel
# command = ["npm" "run" "dev"];
# manager = "web";
# env = {
# # Environment variables to set for your server
# PORT = "$PORT";
# };
# };
};
};
# Workspace lifecycle hooks
workspace = {
# Runs when a workspace is first created
onCreate = {
# Example: install JS dependencies from NPM
# npm-install = "npm install";
# Open editors for the following files by default, if they exist:
default.openFiles = [ "README.md" ];
docker_pull = "docker pull codepathdockerhub/cyber:cyb-101";
};
# Runs when the workspace is (re)started
onStart = {
# Example: start a background task to watch and re-build backend code
docker = "docker pull codepathdockerhub/cyber:cyb-101 && docker run -it --rm --platform linux/amd64 --network host -v /etc/hosts:/etc/hosts --env RESOLVER_PROVIDER=cgo --name codepath-cyb-101 -v $(pwd):/home/codepath/code -p 22:22 -p 3389:3389 codepathdockerhub/cyber:cyb-101";
default.openFiles = [ "README.md" ];
docker_start = "( docker start codepath-cyb-101 &>/dev/null && docker container exec -u 0:0 codepath-cyb-101 su -c 'chown 0:0 /usr/bin/sudo && chmod 4755 /usr/bin/sudo && chown -R codepath: ~codepath' && docker container exec -it codepath-cyb-101 bash ) || docker run -it --name codepath-cyb-101 --volume codepath-cyb-101:/home/codepath codepathdockerhub/cyber:cyb-101";
};
};
};
Expand Down
84 changes: 71 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,71 @@
# cyb-101
IDX Environment Template for CodePath Cyber 101 Course

## Setup
1. Wait a few moments for the environment to load.
2. Open the terminal. You have 2 options:
- Option 1: Click and drag up from the bottom of the screen to open the terminal
- Option 2: Keyboard Shortcut:
- Mac: Command + backtick (the key above the tab key)
- Windows: Ctrl + backtick (the key above the tab key)
- Linux: Ctrl + backtick (the key above the tab key)
3. On the right side, click to open the terminal labeled `docker [onStart]`. We'll use both terminals, but the `docker` terminal is the one we'll use the most, since this is our ubuntu system running in a docker container.
4. The image will take a few minutes to download on the first run. Subsequent starts will be faster.
# README

This repo is used to initalize a Google IDX VM
https://idx.google.com/import?url=https://github.com/clintmint/cyb101-idx

## CYB-101 Google IDX Lab Environment

You should see a terminal at the bottom of this window where you can work on labs and projects. If the terminal panel is missing, you can open it again with a keyboard shortcut:

Windows/Linux
<kbd>⌃ Control</kbd> + <kbd>`</kbd>

macOS
<kbd>⌘ Command</kbd> + <kbd>`</kbd>

It can also be found in the hamburger menu > view > terminal

> Note that Google IDX is still in beta which means it is not yet stable. Make sure you record your project work in the Google Docs template as you make progress just in case the environment becomes corrupted.

## Getting started

Unit specific artifacts are located under your home directory `~`

In the terminal, you change directory to the current unit you are working on by running `cd ~/unit<N>`

Here are some commands to help you move around the filesytem or to understand where you are:

```
codepath@e084ea3c0d16:~$ pwd
/home/codepath
codepath@e084ea3c0d16:~$ ls
Documents john setoolkit startup.sh unit2 unit3 unit6
codepath@e084ea3c0d16:~$ cd unit6
codepath@e084ea3c0d16:~/unit6$ cd ..
codepath@e084ea3c0d16:~$ cd unit2
codepath@e084ea3c0d16:~/unit2$ cd ~/unit6
codepath@e084ea3c0d16:~/unit6$ pwd
/home/codepath/unit6
codepath@e084ea3c0d16:~/unit6$
```

Looking at the shell prompt itself is very useful before running commands.

Example of a shell prompt:

`codepath@e084ea3c0d16:~/unit6$`

By default, the shell prompt, reveals the following:

`user@hostname:<current_working_directory>$`

The `$` indicates that are you logged in as a regular user. If you see `#` on the end, it means you are logged in at the `root` user. The `root` user has maximum privileges so be careful if you login or run commands as root. When we need elevated privileges to perform some action, we can precede the command with `sudo`, "super user do". `sudo` helps certain regular users (belonging to the sudo group) perform privileged operations temporarily without needing to know the `root` user's password.

```
codepath@e084ea3c0d16:~/unit6$ sudo -i
root@e084ea3c0d16:~# whoami
root
root@e084ea3c0d16:~# exit
logout
codepath@e084ea3c0d16:~/unit6$ whoami
codepath
codepath@e084ea3c0d16:~/unit6$
```

With great power comes great responsibility. Save your progress early and often! If you brick the system you can start over by going to the main IDX dashboard at https://idx.google.com/

Then under the workspaces section (bottom right), click the 3 dots to open the settings of cyb101-idx workspace and delete it then reimport it by visiting https://idx.google.com/import?url=https://github.com/clintmint/cyb101-idx

Find the labs and projects here: https://courses.codepath.org

Happy Hacking!
7 changes: 7 additions & 0 deletions idx-template.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{ pkgs, ... }: {
bootstrap = ''
cp -rf ${./.} "$out"
chmod -R +w "$out"
rm -rf "$out/.git" "$out/idx-template".{nix,json}
'';
}