Skip to content

Commit

Permalink
Merge branch 'premaster'
Browse files Browse the repository at this point in the history
  • Loading branch information
mfthomps committed Apr 21, 2023
2 parents aaf71c8 + b64541f commit 97aad08
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 24 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ The installation script and the update-designer.sh script set environment variab
so you may want to logout/login, or start a new bash shell before using Labtainers the
first time.

April 17, 2023
- Force use latest lab version, e.g., iptables2 intead of iptables. Fix tab completion to only display latest. (Issue #77)
- CyberCIEGE lab installation was failing due to X11 race condition. (Issue #76)
- Note in CyberCIEGE readme to direct students to save collected logs in $HOME directory. (Issue #75)
- Radius lab checkwork was incorrectly reporting "radiusd not running", missing prestop script. (Issue #74)
- Labedit corrupted the start configuration file when the MACVLAN\_EXT option was used. (Issue #73)

February 1, 2023
- Bash history for non-default users was not being saved.
January 26, 2023
- Modified powershell scripts for gcloud to use the selected zone to qualify VM names.
January 4, 2023
Expand Down
2 changes: 1 addition & 1 deletion UI/MainUI/src/main/java/labtainers/mainui/LabData.java
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ public String writeStartConfig(boolean usetmp) throws FileNotFoundException{
startConfigText += " MACVLAN "+data.macvlan+"\n";
}
if(data.macvlan_ext > 0){
startConfigText += " MACVLAN_EXT" +data.macvlan_ext+"\n";
startConfigText += " MACVLAN_EXT " +data.macvlan_ext+"\n";
}

if(data.tap){
Expand Down
Binary file modified docs/student/labtainer-student.pdf
Binary file not shown.
12 changes: 10 additions & 2 deletions docs/student/labtainer-student.tex
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,20 @@ \subsection{Google Cloud Platform}

On Mac or Linux:
\begin{itemize}
\item {\tt curl -L \url{https://raw.githubusercontent.com/mfthomps/Labtainers/master/google/install\_labtainers.sh} --output install\_labtainers.sh}
\item Get the install script:
\begin{verbatim}
curl -L https://raw.githubusercontent.com/mfthomps/Labtainers/master/\
google/install_labtainers.sh --output install_labtainers.sh
\end{verbatim}
\item {\tt chmod a+x install\_labtainers.sh}
\end{itemize}
\noindent On Windows:
\begin{itemize}
\item {\tt wget \url{https://raw.githubusercontent.com/mfthomps/Labtainers/master/google/install\_labtainers.ps1} -OutFile install\_labtainers.ps1}
\item Get the script:
\begin{verbatim}
wget https://raw.githubusercontent.com/mfthomps/Labtainers/master/\
google/install_labtainers.ps1 -O install_labtainers.ps1
\end{verbatim}
\end{itemize}

\item Then run it (Mac/Linux).
Expand Down
7 changes: 3 additions & 4 deletions google/create_vm.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Create an Azure VM for a student, assuming the user has
# Create an gcloud VM for a student, assuming the user has
# an Azure account and the CLI installed.
#
# This will create an ssh key pair and use it when creating the VM
Expand All @@ -12,14 +12,13 @@ $ErrorActionPreference = "Stop"
$user_id=$args[0]
$vm_name=$user_id+"-labtainervm"
$zone=./findzone.ps1
gcloud compute instances create $vm_name --image=https://www.googleapis.com/compute/v1/projects/labtainers/global/images/labtainervm5 `
--metadata-from-file=user-data=user_config.txt
gcloud compute instances create $vm_name --image=https://www.googleapis.com/compute/v1/projects/labtainers/global/images/labtainervm5 --metadata-from-file=user-data=user_config.txt --zone=$zone
gcloud compute disks resize $vm_name --size 30G --zone=$zone -q
# instances fail ssh until settled
#
./waitup.ps1 $user_id 2>$null
echo "Check keys"
gcloud compute ssh labtainer@$vm_name --command="echo VM booted" --strict-host-key-checking=no
gcloud compute ssh labtainer@$vm_name --command="echo VM booted" --strict-host-key-checking=no --zone=$zone
#gcloud compute ssh labtainer@$vm_name --dry-run
echo "Back from ssh"
cp $HOME/.ssh/google_compute_engine $HOME/.ssh/id_labtainers
Expand Down
4 changes: 2 additions & 2 deletions google/create_vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ user_id=$1
vm_name=$user_id-labtainervm
zone=$(./findzone.sh)
gcloud compute instances create $vm_name --image=https://www.googleapis.com/compute/v1/projects/labtainers/global/images/labtainervm5 \
--metadata-from-file=user-data=user_config.txt
--metadata-from-file=user-data=user_config.txt --zone=$zone
gcloud compute disks resize $vm_name --size 30G --zone=$zone -q
# instances fail ssh until settled
./waitup.sh $user_id 2>/dev/null
echo "Check keys"
gcloud compute ssh labtainer@$vm_name --command="echo VM booted"
gcloud compute ssh labtainer@$vm_name --command="echo VM booted" --zone=$zone
cp ~/.ssh/google_compute_engine ~/.ssh/id_labtainers
cp ~/.ssh/google_compute_engine.pub ~/.ssh/id_labtainers.pub
./waitdone.sh $user_id
3 changes: 1 addition & 2 deletions google/set_defaults.ps1
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
gcloud compute project-info add-metadata \
--metadata google-compute-default-region=us-west1,google-compute-default-zone=us-west1-b
gcloud compute project-info add-metadata --metadata google-compute-default-region=us-west1,google-compute-default-zone=us-west1-c
3 changes: 3 additions & 0 deletions labs/cyberciege/docs/read_pre.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ For more information about CyberCIEGE, see https://my.nps.edu/web/c3o/cyberciege

This version of CyberCIEGE will not display the tutorial videos from the
Encyclopedia. Please view the videos from https://my.nps.edu/web/c3o/movies

If CyberCIEGE logs are to be collected, save them into the /home/ubuntu directory
using the Collect Logs menu option.
10 changes: 10 additions & 0 deletions labs/radius/radius/_bin/prestop
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
#
# intended for use to advise user who uses checkwork
#
run=$(ps -aux | grep [r]adius)
if [[ ! -z "$run" ]]; then
echo "radiusd running"
else
echo "radiusd is not running"
fi
13 changes: 10 additions & 3 deletions scripts/labtainer-student/bin/labutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1416,11 +1416,17 @@ def DoStartOne(labname, name, container, start_config, labtainer_config, lab_pat

if container.x11.lower() == 'yes':
''' Avoid problems caused by container wiping out all of /tmp on startup '''
cmd = "docker exec %s bash -c 'mkdir -p /var/tmp/.X11-unix'" % (mycontainer_name)
cmd = "docker exec %s bash -c 'mkdir -p /var/tmp/.X11-unix /tmp/.X11-unix'" % (mycontainer_name)
if not DockerCmd(cmd):
logger.error('failed %s' % cmd)
results.append(False)
return

cmd = "docker exec %s bash -c 'ln -s /var/tmp/.X11-unix/X%d /tmp/.X11-unix/X%d'" % (mycontainer_name,
display_num, display_num)
if not doX11Link(cmd):
results.append(False)
return
if not container.no_param:
clone_need_seeds = need_seeds
if not clone_need_seeds:
Expand Down Expand Up @@ -1475,13 +1481,14 @@ def DoStartOne(labname, name, container, start_config, labtainer_config, lab_pat
logger.error('Fatal error in docker command %s' % cmd)
results.append(False)
return

''' repeat x11 because /tmp may have been wiped '''
if container.x11.lower() == 'yes':
cmd = "docker exec %s bash -c 'ln -s /var/tmp/.X11-unix/X%d /tmp/.X11-unix/X%d'" % (mycontainer_name,
cmd = "docker exec %s bash -c 'ln -fs /var/tmp/.X11-unix/X%d /tmp/.X11-unix/X%d'" % (mycontainer_name,
display_num, display_num)
if not doX11Link(cmd):
results.append(False)
return


results.append(retval)

Expand Down
50 changes: 44 additions & 6 deletions scripts/labtainer-student/bin/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ def isLatestVersion(versions, lab):
return False
return True

def getLatestVersion(versions, lab):
retval = lab
if versions is not None:
if lab in versions:
this_version = versions[lab]
#print('this_version is %s' % this_version)
for l in versions:
if versions[l] > this_version:
retval = l
this_version = versions[l]
#print('this_version now %s' % this_version)
return retval

def showLabs(dirs, path, versions, skip):
description = ''
Expand Down Expand Up @@ -112,9 +124,10 @@ def showLabs(dirs, path, versions, skip):
pydoc.pager(description)
print('Use "-h" for help.')

def getRev():
def getRev(labtainer_dir):
created = ""
with open('../../README.md') as fh:
readme = os.path.join(labtainer_dir, 'README.md')
with open(readme) as fh:
for line in fh:
if line.strip().startswith('Distribution created'):
created = line.strip()
Expand Down Expand Up @@ -144,14 +157,27 @@ def checkVersion():
else:
#print('version is %s' % str(sys.version_info))
pass


def printLabList(dirs, path, versions, skip):
for loc in sorted(dirs):
if loc in skip:
continue
versionfile = os.path.join(path, loc, "config", "version")
lname, dumb = getLabVersion(versionfile)
if lname is None or isLatestVersion(versions[lname], loc):
print(loc)

def main():
labtainer_dir = os.getenv('LABTAINER_DIR')
if labtainer_dir is None:
print('LABTAINER_DIR not defined. Cannot run Labtainers.')
exit(1)
checkVersion()
dir_path = os.path.dirname(os.path.realpath(__file__))
dir_path = dir_path[:dir_path.index("scripts/labtainer-student")]
path = dir_path + "labs/"
dirs = os.listdir(path)
rev = getRev()
rev = getRev(labtainer_dir)
#revision='%(prog)s %s' % rev
parser = argparse.ArgumentParser(prog='labtainer', description='Start a Labtainers lab. Provide no arguments to see a list of labs.')
parser.add_argument('labname', default='NONE', nargs='?', action='store', help='The lab to run')
Expand All @@ -166,6 +192,7 @@ def main():
parser.add_argument('-n', '--client_count', action='store', help='Number of clones of client components to create, intended for multi-user labs')
parser.add_argument('-o', '--only_container', action='store', help='Run only the named container')
parser.add_argument('-t', '--test_registry', action='store_true', default=False, help='Run with images from the test registry')
parser.add_argument('-l', '--list', action='store_true', default=False, help='Print list of labs. Use no options for verbose list.')
num_args = len(sys.argv)
versions = getVerList(dirs, path)
skip_labs = os.path.join(dir_path, 'distrib', 'skip-labs')
Expand All @@ -185,6 +212,9 @@ def main():
if args.find is not None:
keywords.find(' '.join(args.find))
exit(0)
if args.list:
printLabList(dirs, path, versions, skip)
exit(0)
labname = args.labname
if labname == 'NONE' and not args.diagnose:
sys.stderr.write("Missing lab name\n")
Expand All @@ -194,13 +224,21 @@ def main():
diagnose()
if labname == 'NONE':
exit(0)

if labname not in dirs:
sys.stderr.write("ERROR: Lab named %s was not found.\n" % labname)
sys.stderr.write("Make sure you have all the latest labs by running:\n")
sys.stderr.write(" update-labtainer.sh\n")
sys.exit(1)

lpath = os.path.join(path, labname, 'config', 'version')
lname, version = getLabVersion(lpath)
if lname is not None:
latest_lab = getLatestVersion(versions[lname], labname)
if labname != latest_lab:
print('Lab %s has been deprecated, will run %s instead.' % (labname, latest_lab))
labname = latest_lab

if labname in skip:
print('Warning, %s has been deprecated and is no longer supported. It may not work as expected.' % labname)

Expand Down Expand Up @@ -240,7 +278,7 @@ def main():
labutils.RedoLab(lab_path, quiet_start=args.quiet,
run_container=args.only_container, servers=distributed, clone_count=args.client_count)
current_lab = CurrentLab.CurrentLab()
current_lab.add('lab_name', args.labname)
current_lab.add('lab_name', labname)
current_lab.add('clone_count', args.client_count)
current_lab.add('servers', distributed)
current_lab.save()
Expand Down
2 changes: 1 addition & 1 deletion scripts/labtainer-student/lab_bin/parameterize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ userlist=$(ls /home)
for user in $userlist; do
if [ $user != $CONTAINER_USER ]; then
''' Append history to bash_history and set terminal title which gets trashed by the PROMPT_COMMAND '''
echo "export PROMPT_COMMAND='history -a;echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007\"'"
echo "export PROMPT_COMMAND='history -a;echo -ne \"\033]0;$user@${HOSTNAME}: ${PWD/$HOME/~}\007\"'" >> /home/$user/.bash_profile
fi
done

Expand Down
2 changes: 1 addition & 1 deletion setup_scripts/install-docker-ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ sudo usermod -aG docker $USER
#---other packages required by Labtainers
sudo apt-get -y install python3-pip
sudo -H pip3 install --upgrade pip3
sudo -H pip3 install netaddr parse python-dateutil
sudo -H pip3 install netaddr parse python-dateutil docker
sudo apt-get -y install openssh-server

#---Checking if packages have been installed. If not, the system will not reboot and allow the user to investigate.
Expand Down
3 changes: 1 addition & 2 deletions setup_scripts/lab-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
#
# Get list of labtainer labs
#
ldir=$LABTAINER_DIR/labs
lablist=$(ls $ldir)
lablist=$($LABTAINER_DIR/scripts/labtainer-student/bin/start.py -l)
# replace newlines with spaces
lablist="${lablist//$'\n'/ }"
# tell bash to use this list for tab completion of the "labtainer" command.
Expand Down

0 comments on commit 97aad08

Please sign in to comment.