diff --git a/BINSCRIPTS.md b/BINSCRIPTS.md deleted file mode 100644 index f5949ba..0000000 --- a/BINSCRIPTS.md +++ /dev/null @@ -1,41 +0,0 @@ -# util - -This repository is intended to be downloaded into a container repository during development for convenience purposes. Since the major mechanisms of developing to the Docker container construction lifecycle are identical across container images, this repository allows for consistency and additional ease of use across all container images. - -## Install - -If you are reading this file in BINSCRIPTS.md, your container project is likely to be util-enabled. - -To use these scripts yourself, issue this command: - -``` -curl "https://github.internet2.edu/raw/docker/util/master/bin/install.sh?token=AAAAETsVKUnOEAMM8TvUUZccPYi13wsnks5Xq46jwA%3D%3D" | bash -``` - -### common.bash - -The installation process will create a common.bash file. This file should be the central, canonical authority for management of environment variables. While a subprocess may override them, the files in common.bash should be treated as authoritative defaults. Processes (e.g. `docker build`, `bats`, inside `Jenkinsfile`) can read this file and process the results therein. - -You should edit this file to change the image name, and add any other helpful environment variables. - -### Jenkinsfile - -This will also install a Jenkinsfile to your repository, if it doesn't have one. This will ensure that your Jenkins pipeline can leverage these scripts in the way intended. Ensuring the commands that you issue on your laptop match the commands issued by the build pipeline is critical to ensure predictable, reliable results. - -## Use - - -### Building - -#### build.sh -`bin/build.sh ` -#### destroy.sh -#### rebuild.sh - -### Running -### rerun.sh -### run.sh - - -### Testing -#### test.sh \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 3d6a5cf..8d96741 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,9 @@ -FROM tier/centos7base +FROM centos:centos7 # Define args and set a default value ARG maintainer=tier ARG imagename=shibboleth_sp -ARG version=2.6.1 +ARG version=3.0.4 MAINTAINER $maintainer LABEL Vendor="Internet2" @@ -14,31 +14,64 @@ LABEL Version=$version LABEL Build docker build --rm --tag $maintainer/$imagename . -# Add starters and installers -ADD ./container_files /opt +RUN ln -sf /usr/share/zoneinfo/UTC /etc/localtime \ + && echo "NETWORKING=yes" > /etc/sysconfig/network +RUN rm -fr /var/cache/yum/* && yum clean all && yum -y install --setopt=tsflags=nodocs epel-release && yum -y update && \ + yum -y install net-tools wget curl tar unzip mlocate logrotate strace telnet man vim rsyslog cron httpd mod_ssl dos2unix cronie supervisor && \ + yum clean all + +#install shibboleth, cleanup httpd RUN curl -o /etc/yum.repos.d/security:shibboleth.repo \ http://download.opensuse.org/repositories/security://shibboleth/CentOS_7/security:shibboleth.repo \ - && yum -y update \ - && yum -y install \ - httpd \ - mod_ssl \ - shibboleth.x86_64 \ - dos2unix \ + && yum -y install shibboleth.x86_64 \ && yum clean all \ && rm /etc/httpd/conf.d/autoindex.conf \ - && rm /etc/httpd/conf.d/ssl.conf \ && rm /etc/httpd/conf.d/userdir.conf \ - && rm /etc/httpd/conf.d/welcome.conf \ - && chmod +x /opt/bin/httpd-shib-foreground \ - && chmod +x /opt/bin/shibboleth_keygen.sh + && rm /etc/httpd/conf.d/welcome.conf # Export this variable so that shibd can find its CURL library RUN LD_LIBRARY_PATH="/opt/shibboleth/lib64" RUN export LD_LIBRARY_PATH -#Script to start service, Added ssl default conf, Added shib module apache -RUN ln -s /opt/bin/httpd-shib-foreground /usr/local/bin && ln -s /opt/etc/httpd/conf.d/ssl.conf /etc/httpd/conf.d/ssl.conf && ln -s /opt/etc/httpd/conf.modules.d/00-shib.conf /etc/httpd/conf.modules.d/00-shib.conf && ln -s /usr/lib64/shibboleth/mod_shib_24.so /etc/httpd/modules/mod_shib_24.so +ADD ./container_files/httpd/ssl.conf /etc/httpd/conf.d/ +ADD ./container_files/shibboleth/* /etc/shibboleth/ + +# fix httpd logging to tier format +RUN sed -i 's/LogFormat "/LogFormat "httpd;access_log;%{ENV}e;%{USERTOKEN}e;/g' /etc/httpd/conf/httpd.conf \ + && echo -e "\nErrorLogFormat \"httpd;error_log;%{ENV}e;%{USERTOKEN}e;[%{u}t] [%-m:%l] [pid %P:tid %T] %7F: %E: [client\ %a] %M% ,\ referer\ %{Referer}i\"" >> /etc/httpd/conf/httpd.conf \ + && sed -i 's/CustomLog "logs\/access_log"/CustomLog "\/tmp\/logpipe"/g' /etc/httpd/conf/httpd.conf \ + && sed -i 's/ErrorLog "logs\/error_log"/ErrorLog "\/tmp\/logpipe"/g' /etc/httpd/conf/httpd.conf \ + && echo -e "\nPassEnv ENV" >> /etc/httpd/conf/httpd.conf \ + && echo -e "\nPassEnv USERTOKEN" >> /etc/httpd/conf/httpd.conf \ + && sed -i '/UseCanonicalName/c\UseCanonicalName On' /etc/httpd/conf/httpd.conf + +# add a basic page to shibb's default protected directory +RUN mkdir -p /var/www/html/secure/; mkdir -p /opt/tier/ +ADD container_files/httpd/index.html /var/www/html/secure/ + + +# setup crond and supervisord +ADD container_files/system/startup.sh /usr/local/bin/ +ADD container_files/system/setupcron.sh /usr/local/bin/ +ADD container_files/system/setenv.sh /opt/tier/ +ADD container_files/system/sendtierbeacon.sh /usr/local/bin/ +ADD container_files/system/supervisord.conf /etc/supervisor/ +RUN mkdir -p /etc/supervisor/conf.d \ + && chmod +x /usr/local/bin/setupcron.sh \ + && chmod +x /usr/local/bin/sendtierbeacon.sh \ +# setup cron + && /usr/local/bin/setupcron.sh + +#set cron to not require a login session +RUN sed -i '/session required pam_loginuid.so/c\#session required pam_loginuid.so' /etc/pam.d/crond + EXPOSE 80 443 -CMD ["httpd-shib-foreground"] + +HEALTHCHECK --interval=1m --timeout=30s \ + CMD curl -k -f https://127.0.0.1:8443/Shibboleth.sso/Status || exit 1 + + +CMD ["/usr/local/bin/startup.sh"] + diff --git a/Jenkinsfile b/Jenkinsfile index 00be48b..74578ef 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -11,6 +11,7 @@ node('docker') { git([ url: "https://github.internet2.edu/docker/util.git", credentialsId: "jenkins-github-access-token" ]) sh 'ls' + sh 'rm -rf ../bin/windows/' sh 'mv bin/* ../bin/.' } stage 'Setting build context' @@ -39,7 +40,7 @@ node('docker') { sh 'bin/rebuild.sh &> debug' } catch(error) { def error_details = readFile('./debug'); - def message = "BUILD ERROR: There was a problem building the shibboleth-sp mage. \n\n ${error_details}" + def message = "BUILD ERROR: There was a problem building the shibboleth-sp image. \n\n ${error_details}" sh "rm -f ./debug" handleError(message) } diff --git a/README.md b/README.md index 3f96763..32be5b5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,36 @@ -# shibboleth-sp +# TIER shibboleth-sp [![Build Status](https://jenkins.testbed.tier.internet2.edu/buildStatus/icon?job=docker/shib-sp/master)](https://jenkins.testbed.tier.internet2.edu/job/docker/shib-sp/master) -This image is the parent of COmanage and Grouper containers, as it contains the OpenSUSE repositories for shibboleth package management, and an apache installation. +This is the TIER upstream Shibboleth SP container. + +It is based from CentOS 7 and includes httpd, mod_ssl, and the current shibboleth SP. + +Files you must supply/override in your downstream builds: + +1. The SP's ***private keys and corresponding certificates*** (very important!), which can be generated in your downstream container like this: +> RUN /etc/shibboleth/keygen.sh -o /etc/shibboleth/ -y 10 -n sp-encrypt -f \ +> && /etc/shibboleth/keygen.sh -o /etc/shibboleth/ -y 10 -n sp-signing -f +> +> ...those commands generate/overwrite the following files: +> /etc/shibboleth/sp-encrypt-key.pem +> /etc/shibboleth/sp-encrypt-cert.pem +> /etc/shibboleth/sp-signing-key.pem +> /etc/shibboleth/sp-signing-cert.pem + +2. ***/etc/httpd/conf.d/ssl.conf*** +> including: +> ServerName fqdn:port +> UseCanonicalName On + +3. ***/etc/shibboleth/shibboleth2.xml*** +> including: +> entityID +

+ ***New in the 3.0 release:*** +* The image is based from the public CentOS7 image +* The TIER logging format has been implemented for shibd and httpd +* Everything now runs under supervisord +* The TIER Beacon has been implemented +* The file */etc/httpd/conf.d/ssl.conf* is now the default CentOS7 file diff --git a/bin/ci-run.sh b/bin/ci-run.sh index 70761f0..4ef1dc0 100755 --- a/bin/ci-run.sh +++ b/bin/ci-run.sh @@ -3,4 +3,5 @@ # This file will run a container in the background source common.bash . -docker run -d --name=$imagename -p 80:80 -p 443:443 $maintainer/$imagename \ No newline at end of file +docker run -d --name=$imagename -p 80:80 -p 443:443 $maintainer/$imagename + diff --git a/bin/ci-stop.sh b/bin/ci-stop.sh index 54ab019..60c6f27 100755 --- a/bin/ci-stop.sh +++ b/bin/ci-stop.sh @@ -6,3 +6,4 @@ source common.bash . echo "Cleaning up Docker image($maintainer/$imagename)" docker stop $imagename >> /dev/null docker rm $imagename + diff --git a/common.bash b/common.bash index 362ce33..2053ebe 100644 --- a/common.bash +++ b/common.bash @@ -1,3 +1,3 @@ maintainer="tier" imagename="shibboleth_sp" -version="2.5.1" \ No newline at end of file +version="3.0.3" diff --git a/container_files/bin/httpd-shib-foreground b/container_files/bin/httpd-shib-foreground deleted file mode 100755 index 60a415f..0000000 --- a/container_files/bin/httpd-shib-foreground +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh -set -e - -# Apache gets grumpy about PID files pre-existing -rm -f /etc/httpd/logs/httpd.pid - -(/usr/sbin/shibd) & httpd -DFOREGROUND diff --git a/container_files/bin/shibboleth_keygen.sh b/container_files/bin/shibboleth_keygen.sh deleted file mode 100755 index 205792e..0000000 --- a/container_files/bin/shibboleth_keygen.sh +++ /dev/null @@ -1,75 +0,0 @@ -#! /bin/sh - -while getopts h:u:g:o:e:y:bf c - do - case $c in - o) OUT=$OPTARG;; - b) BATCH=1;; - f) FORCE=1;; - h) FQDN=$OPTARG;; - e) ENTITYID=$OPTARG;; - y) YEARS=$OPTARG;; - \?) echo "shibboleth_keygen [-o output directory (default .)] [-h hostname for cert] [-y years to issue cert] [-e entityID to embed in cert]" - exit 1;; - esac - done -if [ -z "$OUT" ] ; then - OUT=. -fi - -if [ -n "$FORCE" ] ; then - rm $OUT/sp-key.pem $OUT/sp-cert.pem -fi - -if [ -s $OUT/sp-key.pem -o -s $OUT/sp-cert.pem ] ; then - if [ -z "$BATCH" ] ; then - echo The files $OUT/sp-key.pem and/or $OUT/sp-cert.pem already exist! - echo Use -f option to force recreation of keypair. - exit 2 - fi - exit 0 -fi - -if [ -z "$FQDN" ] ; then - FQDN=`hostname --fqdn` -fi - -if [ -z "$YEARS" ] ; then - YEARS=10 -fi - -DAYS=`expr $YEARS \* 365` - -if [ -z "$ENTITYID" ] ; then - ALTNAME=DNS:$FQDN -else - ALTNAME=DNS:$FQDN,URI:$ENTITYID -fi - -SSLCNF=$OUT/sp-cert.cnf -cat >$SSLCNF < /dev/null -fi -rm $SSLCNF \ No newline at end of file diff --git a/container_files/etc/httpd/conf.d/ssl.conf b/container_files/etc/httpd/conf.d/ssl.conf deleted file mode 100644 index ccc067c..0000000 --- a/container_files/etc/httpd/conf.d/ssl.conf +++ /dev/null @@ -1,6 +0,0 @@ -SSLPassPhraseDialog exec:/usr/libexec/httpd-ssl-pass-dialog -SSLSessionCache shmcb:/run/httpd/sslcache(512000) -SSLSessionCacheTimeout 300 -SSLRandomSeed startup file:/dev/urandom 256 -SSLRandomSeed connect builtin -SSLCryptoDevice builtin diff --git a/container_files/etc/httpd/conf.modules.d/00-shib.conf b/container_files/etc/httpd/conf.modules.d/00-shib.conf deleted file mode 100644 index 0e5c7b2..0000000 --- a/container_files/etc/httpd/conf.modules.d/00-shib.conf +++ /dev/null @@ -1 +0,0 @@ -LoadModule mod_shib /usr/lib64/shibboleth/mod_shib_24.so diff --git a/container_files/etc/shibboleth/attribute-map.xml b/container_files/etc/shibboleth/attribute-map.xml deleted file mode 100644 index 12c4019..0000000 --- a/container_files/etc/shibboleth/attribute-map.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/container_files/httpd/index.html b/container_files/httpd/index.html new file mode 100644 index 0000000..9b3dd7a --- /dev/null +++ b/container_files/httpd/index.html @@ -0,0 +1,3 @@ +
+

This page is protected by the Shibboleth SP.

+ diff --git a/container_files/httpd/ssl.conf b/container_files/httpd/ssl.conf new file mode 100644 index 0000000..3eec310 --- /dev/null +++ b/container_files/httpd/ssl.conf @@ -0,0 +1,217 @@ +# +# When we also provide SSL we have to listen to the +# the HTTPS port in addition. +# +Listen 443 https + +## +## SSL Global Context +## +## All SSL configuration in this context applies both to +## the main server and all SSL-enabled virtual hosts. +## + +# Pass Phrase Dialog: +# Configure the pass phrase gathering process. +# The filtering dialog program (`builtin' is a internal +# terminal dialog) has to provide the pass phrase on stdout. +SSLPassPhraseDialog exec:/usr/libexec/httpd-ssl-pass-dialog + +# Inter-Process Session Cache: +# Configure the SSL Session Cache: First the mechanism +# to use and second the expiring timeout (in seconds). +SSLSessionCache shmcb:/run/httpd/sslcache(512000) +SSLSessionCacheTimeout 300 + +# Pseudo Random Number Generator (PRNG): +# Configure one or more sources to seed the PRNG of the +# SSL library. The seed data should be of good random quality. +# WARNING! On some platforms /dev/random blocks if not enough entropy +# is available. This means you then cannot use the /dev/random device +# because it would lead to very long connection times (as long as +# it requires to make more entropy available). But usually those +# platforms additionally provide a /dev/urandom device which doesn't +# block. So, if available, use this one instead. Read the mod_ssl User +# Manual for more details. +SSLRandomSeed startup file:/dev/urandom 256 +SSLRandomSeed connect builtin +#SSLRandomSeed startup file:/dev/random 512 +#SSLRandomSeed connect file:/dev/random 512 +#SSLRandomSeed connect file:/dev/urandom 512 + +# +# Use "SSLCryptoDevice" to enable any supported hardware +# accelerators. Use "openssl engine -v" to list supported +# engine names. NOTE: If you enable an accelerator and the +# server does not start, consult the error logs and ensure +# your accelerator is functioning properly. +# +SSLCryptoDevice builtin +#SSLCryptoDevice ubsec + +## +## SSL Virtual Host Context +## + + + +# General setup for the virtual host, inherited from global configuration +#DocumentRoot "/var/www/html" +#ServerName www.example.com:443 + +# Use separate log files for the SSL virtual host; note that LogLevel +# is not inherited from httpd.conf. +ErrorLog logs/ssl_error_log +TransferLog logs/ssl_access_log +LogLevel warn + +# SSL Engine Switch: +# Enable/Disable SSL for this virtual host. +SSLEngine on + +# SSL Protocol support: +# List the enable protocol levels with which clients will be able to +# connect. Disable SSLv2 access by default: +SSLProtocol all -SSLv2 -SSLv3 + +# SSL Cipher Suite: +# List the ciphers that the client is permitted to negotiate. +# See the mod_ssl documentation for a complete list. +SSLCipherSuite HIGH:3DES:!aNULL:!MD5:!SEED:!IDEA + +# Speed-optimized SSL Cipher configuration: +# If speed is your main concern (on busy HTTPS servers e.g.), +# you might want to force clients to specific, performance +# optimized ciphers. In this case, prepend those ciphers +# to the SSLCipherSuite list, and enable SSLHonorCipherOrder. +# Caveat: by giving precedence to RC4-SHA and AES128-SHA +# (as in the example below), most connections will no longer +# have perfect forward secrecy - if the server's key is +# compromised, captures of past or future traffic must be +# considered compromised, too. +#SSLCipherSuite RC4-SHA:AES128-SHA:HIGH:MEDIUM:!aNULL:!MD5 +#SSLHonorCipherOrder on + +# Server Certificate: +# Point SSLCertificateFile at a PEM encoded certificate. If +# the certificate is encrypted, then you will be prompted for a +# pass phrase. Note that a kill -HUP will prompt again. A new +# certificate can be generated using the genkey(1) command. +SSLCertificateFile /etc/pki/tls/certs/localhost.crt + +# Server Private Key: +# If the key is not combined with the certificate, use this +# directive to point at the key file. Keep in mind that if +# you've both a RSA and a DSA private key you can configure +# both in parallel (to also allow the use of DSA ciphers, etc.) +SSLCertificateKeyFile /etc/pki/tls/private/localhost.key + +# Server Certificate Chain: +# Point SSLCertificateChainFile at a file containing the +# concatenation of PEM encoded CA certificates which form the +# certificate chain for the server certificate. Alternatively +# the referenced file can be the same as SSLCertificateFile +# when the CA certificates are directly appended to the server +# certificate for convinience. +#SSLCertificateChainFile /etc/pki/tls/certs/server-chain.crt + +# Certificate Authority (CA): +# Set the CA certificate verification path where to find CA +# certificates for client authentication or alternatively one +# huge file containing all of them (file must be PEM encoded) +#SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt + +# Client Authentication (Type): +# Client certificate verification type and depth. Types are +# none, optional, require and optional_no_ca. Depth is a +# number which specifies how deeply to verify the certificate +# issuer chain before deciding the certificate is not valid. +#SSLVerifyClient require +#SSLVerifyDepth 10 + +# Access Control: +# With SSLRequire you can do per-directory access control based +# on arbitrary complex boolean expressions containing server +# variable checks and other lookup directives. The syntax is a +# mixture between C and Perl. See the mod_ssl documentation +# for more details. +# +#SSLRequire ( %{SSL_CIPHER} !~ m/^(EXP|NULL)/ \ +# and %{SSL_CLIENT_S_DN_O} eq "Snake Oil, Ltd." \ +# and %{SSL_CLIENT_S_DN_OU} in {"Staff", "CA", "Dev"} \ +# and %{TIME_WDAY} >= 1 and %{TIME_WDAY} <= 5 \ +# and %{TIME_HOUR} >= 8 and %{TIME_HOUR} <= 20 ) \ +# or %{REMOTE_ADDR} =~ m/^192\.76\.162\.[0-9]+$/ +# + +# SSL Engine Options: +# Set various options for the SSL engine. +# o FakeBasicAuth: +# Translate the client X.509 into a Basic Authorisation. This means that +# the standard Auth/DBMAuth methods can be used for access control. The +# user name is the `one line' version of the client's X.509 certificate. +# Note that no password is obtained from the user. Every entry in the user +# file needs this password: `xxj31ZMTZzkVA'. +# o ExportCertData: +# This exports two additional environment variables: SSL_CLIENT_CERT and +# SSL_SERVER_CERT. These contain the PEM-encoded certificates of the +# server (always existing) and the client (only existing when client +# authentication is used). This can be used to import the certificates +# into CGI scripts. +# o StdEnvVars: +# This exports the standard SSL/TLS related `SSL_*' environment variables. +# Per default this exportation is switched off for performance reasons, +# because the extraction step is an expensive operation and is usually +# useless for serving static content. So one usually enables the +# exportation for CGI and SSI requests only. +# o StrictRequire: +# This denies access when "SSLRequireSSL" or "SSLRequire" applied even +# under a "Satisfy any" situation, i.e. when it applies access is denied +# and no other module can change it. +# o OptRenegotiate: +# This enables optimized SSL connection renegotiation handling when SSL +# directives are used in per-directory context. +#SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire + + SSLOptions +StdEnvVars + + + SSLOptions +StdEnvVars + + +# SSL Protocol Adjustments: +# The safe and default but still SSL/TLS standard compliant shutdown +# approach is that mod_ssl sends the close notify alert but doesn't wait for +# the close notify alert from client. When you need a different shutdown +# approach you can use one of the following variables: +# o ssl-unclean-shutdown: +# This forces an unclean shutdown when the connection is closed, i.e. no +# SSL close notify alert is send or allowed to received. This violates +# the SSL/TLS standard but is needed for some brain-dead browsers. Use +# this when you receive I/O errors because of the standard approach where +# mod_ssl sends the close notify alert. +# o ssl-accurate-shutdown: +# This forces an accurate shutdown when the connection is closed, i.e. a +# SSL close notify alert is send and mod_ssl waits for the close notify +# alert of the client. This is 100% SSL/TLS standard compliant, but in +# practice often causes hanging connections with brain-dead browsers. Use +# this only for browsers where you know that their SSL implementation +# works correctly. +# Notice: Most problems of broken clients are also related to the HTTP +# keep-alive facility, so you usually additionally want to disable +# keep-alive for those clients, too. Use variable "nokeepalive" for this. +# Similarly, one has to force some clients to use HTTP/1.0 to workaround +# their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and +# "force-response-1.0" for this. +BrowserMatch "MSIE [2-5]" \ + nokeepalive ssl-unclean-shutdown \ + downgrade-1.0 force-response-1.0 + +# Per-Server Logging: +# The home of a custom SSL log file. Use this when you want a +# compact non-error SSL logfile on a virtual host basis. +CustomLog logs/ssl_request_log \ + "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b" + + + diff --git a/container_files/etc/shibboleth/inc-md-cert.pem b/container_files/shibboleth/inc-md-cert.pem similarity index 100% rename from container_files/etc/shibboleth/inc-md-cert.pem rename to container_files/shibboleth/inc-md-cert.pem diff --git a/container_files/shibboleth/native.logger b/container_files/shibboleth/native.logger new file mode 100644 index 0000000..1f01974 --- /dev/null +++ b/container_files/shibboleth/native.logger @@ -0,0 +1,40 @@ +# set overall behavior +log4j.rootCategory=INFO, native_log, warn_log + +# fairly verbose for DEBUG, so generally leave at INFO +log4j.category.XMLTooling.XMLObject=INFO +log4j.category.XMLTooling.KeyInfoResolver=INFO +log4j.category.Shibboleth.IPRange=INFO +log4j.category.Shibboleth.PropertySet=INFO + +# raise for low-level tracing of SOAP client HTTP/SSL behavior +log4j.category.XMLTooling.libcurl=INFO + +# useful categories to tune independently: +# +# tracing of SAML messages and security policies +#log4j.category.OpenSAML.MessageDecoder=DEBUG +#log4j.category.OpenSAML.MessageEncoder=DEBUG +#log4j.category.OpenSAML.SecurityPolicyRule=DEBUG +# interprocess message remoting +#log4j.category.Shibboleth.Listener=DEBUG +# mapping of requests to applicationId +#log4j.category.Shibboleth.RequestMapper=DEBUG +# high level session cache operations +#log4j.category.Shibboleth.SessionCache=DEBUG +# persistent storage and caching +#log4j.category.XMLTooling.StorageService=DEBUG + +# define the appender + +log4j.appender.native_log=org.apache.log4j.FileAppender +log4j.appender.native_log.fileName=/tmp/logpipe +log4j.appender.native_log.layout=org.apache.log4j.PatternLayout +log4j.appender.native_log.layout.ConversionPattern=shibd;native.log;${ENV};${USERTOKEN};%d{%Y-%m-%d %H:%M:%S} %p %c %x: %m%n + +log4j.appender.warn_log=org.apache.log4j.FileAppender +log4j.appender.warn_log.fileName=/tmp/logpipe +log4j.appender.warn_log.layout=org.apache.log4j.PatternLayout +log4j.appender.warn_log.layout.ConversionPattern=shibd;native_warn.log;${ENV};${USERTOKEN};%d{%Y-%m-%d %H:%M:%S} %p %c %x: %m%n +log4j.appender.warn_log.threshold=WARN + diff --git a/container_files/shibboleth/shibd.logger b/container_files/shibboleth/shibd.logger new file mode 100644 index 0000000..d3b26cd --- /dev/null +++ b/container_files/shibboleth/shibd.logger @@ -0,0 +1,60 @@ +# set overall behavior +log4j.rootCategory=INFO, shibd_log + +# fairly verbose for DEBUG, so generally leave at INFO +log4j.category.XMLTooling.XMLObject=INFO +log4j.category.XMLTooling.KeyInfoResolver=INFO +log4j.category.Shibboleth.IPRange=INFO +log4j.category.Shibboleth.PropertySet=INFO + +# raise for low-level tracing of SOAP client HTTP/SSL behavior +log4j.category.XMLTooling.libcurl=INFO + +# useful categories to tune independently: +# +# tracing of SAML messages and security policies +#log4j.category.OpenSAML.MessageDecoder=DEBUG +#log4j.category.OpenSAML.MessageEncoder=DEBUG +#log4j.category.OpenSAML.SecurityPolicyRule=DEBUG +#log4j.category.XMLTooling.SOAPClient=DEBUG +# interprocess message remoting +#log4j.category.Shibboleth.Listener=DEBUG +# mapping of requests to applicationId +#log4j.category.Shibboleth.RequestMapper=DEBUG +# high level session cache operations +#log4j.category.Shibboleth.SessionCache=DEBUG +# persistent storage and caching +#log4j.category.XMLTooling.StorageService=DEBUG + +# logs XML being signed or verified if set to DEBUG +log4j.category.XMLTooling.Signature.Debugger=INFO, sig_log +log4j.additivity.XMLTooling.Signature.Debugger=false + +# the tran log blocks the "default" appender(s) at runtime +# Level should be left at INFO for this category +log4j.category.Shibboleth-TRANSACTION=INFO, tran_log +log4j.additivity.Shibboleth-TRANSACTION=false +# uncomment to suppress particular event types +#log4j.category.Shibboleth-TRANSACTION.AuthnRequest=WARN +#log4j.category.Shibboleth-TRANSACTION.Login=WARN +#log4j.category.Shibboleth-TRANSACTION.Logout=WARN + +# define the appenders + +log4j.appender.shibd_log=org.apache.log4j.FileAppender +log4j.appender.shibd_log.fileName=/tmp/logpipe +log4j.appender.shibd_log.maxFileSize=0 +log4j.appender.shibd_log.layout=org.apache.log4j.PatternLayout +log4j.appender.shibd_log.layout.ConversionPattern=shibd;shibd.log;${ENV};${USERTOKEN};%d{%Y-%m-%d %H:%M:%S} %p %c %x: %m%n + +log4j.appender.tran_log=org.apache.log4j.FileAppender +log4j.appender.tran_log.fileName=/tmp/logpipe +log4j.appender.tran_log.maxFileSize=0 +log4j.appender.tran_log.layout=org.apache.log4j.PatternLayout +log4j.appender.tran_log.layout.ConversionPattern=shibd;transaction.log;${ENV};${USERTOKEN};%d{%Y-%m-%d %H:%M:%S} %p %c %x: %m%n + +log4j.appender.sig_log=org.apache.log4j.FileAppender +log4j.appender.sig_log.fileName=/tmp/logpipe +log4j.appender.sig_log.layout=org.apache.log4j.PatternLayout +log4j.appender.sig_log.layout.ConversionPattern=shibd;signature.log;${ENV};${USERTOKEN};%m + diff --git a/container_files/system/sendtierbeacon.sh b/container_files/system/sendtierbeacon.sh new file mode 100755 index 0000000..7496968 --- /dev/null +++ b/container_files/system/sendtierbeacon.sh @@ -0,0 +1,28 @@ +#!/bin/bash +LOGHOST="collector.testbed.tier.internet2.edu" +LOGPORT="5001" +if [ -s /opt/tier/env.bash ]; then + . /opt/tier/env.bash +fi + +#JSON/REST style +LOGTEXT="{ \"msgType\" : \"TIERBEACON\", \"msgName\" : \"TIER\", \"msgVersion\" : \"1.0\", \"tbProduct\" : \"$IMAGENAME\", \"tbProductVersion\" : \"$VERSION\", \"tbTIERRelease\" : \"$TIERVERSION\", \"tbMaintainer\" : \"$MAINTAINER\" }" + + +if [ -z "$TIER_BEACON_OPT_OUT" ]; then + #send JSON + echo $LOGTEXT > msgjson.txt + curl -s -XPOST "${LOGHOST}:${LOGPORT}/" -H 'Content-Type: application/json' -T msgjson.txt 1>/dev/null + if [ $? -eq 0 ]; then + echo "tier_beacon;none;$ENV;$USERTOKEN;"`date`"; TIER beacon sent" + else + echo "tier_beacon;none;$ENV;$USERTOKEN;"`date`"; Failed to send TIER beacon" + fi + + rm -f msgjson.txt + + #below is for syslog, F-TICKS style + #`logger -n $LOGHOST -P $LOGPORT -t TIERBEACON $LOGTEXT` + +fi + diff --git a/container_files/system/setenv.sh b/container_files/system/setenv.sh new file mode 100755 index 0000000..55c8c89 --- /dev/null +++ b/container_files/system/setenv.sh @@ -0,0 +1,6 @@ +#!/bin/bash +printenv | sed 's/^\(.*\)$/\1/g' | grep -E "^VERSION" > /opt/tier/env.bash +printenv | sed 's/^\(.*\)$/\1/g' | grep -E "^TIERVERSION" >> /opt/tier/env.bash +printenv | sed 's/^\(.*\)$/\1/g' | grep -E "^IMAGE" >> /opt/tier/env.bash +printenv | sed 's/^\(.*\)$/\1/g' | grep -E "^MAINTAINER" >> /opt/tier/env.bash + diff --git a/container_files/system/setupcron.sh b/container_files/system/setupcron.sh new file mode 100755 index 0000000..3cabd35 --- /dev/null +++ b/container_files/system/setupcron.sh @@ -0,0 +1,18 @@ +#!/bin/bash +CRONFILE=/opt/tier/tier-cron + +#set env vars for cron job +# this script creates /opt/tier/env.bash which is sourced by the cron job's script, which was not seeing the environment set by the Dockerfile +/opt/tier/setenv.sh + +#build crontab file with random start time between midnight and 3:59am +echo "#send daily beacon to TIER Central" > ${CRONFILE} +echo $(expr $RANDOM % 59) $(expr $RANDOM % 3) "* * * /usr/local/bin/sendtierbeacon.sh >> /var/log/cron.log 2>&1" >> ${CRONFILE} +chmod 644 ${CRONFILE} + +#install crontab +crontab ${CRONFILE} + +#create cron logfile +touch /var/log/cron.log + diff --git a/container_files/system/shibboleth_keygen.sh b/container_files/system/shibboleth_keygen.sh new file mode 100644 index 0000000..f6d17ab --- /dev/null +++ b/container_files/system/shibboleth_keygen.sh @@ -0,0 +1,92 @@ +#! /bin/sh + +while getopts n:h:u:g:o:e:y:bf c + do + case $c in + u) USER=$OPTARG;; + g) GROUP=$OPTARG;; + o) OUT=$OPTARG;; + b) BATCH=1;; + f) FORCE=1;; + h) FQDN=$OPTARG;; + e) ENTITYID=$OPTARG;; + y) YEARS=$OPTARG;; + n) PREFIX=$OPTARG;; + \?) echo "keygen [-o output directory (default .)] [-u username to own keypair] [-g owning groupname] [-h hostname for cert] [-y years to issue cert] [-e entityID to embed in cert] [-n filename prefix (default 'sp')]" + exit 1;; + esac + done + +if [ -z "$OUT" ] ; then + OUT=. +fi + +if [ -z "$PREFIX" ]; then + PREFIX="sp" +fi + +if [ -n "$FORCE" ] ; then + rm $OUT/${PREFIX}-key.pem $OUT/${PREFIX}-cert.pem +fi + +if [ -s $OUT/${PREFIX}-key.pem -o -s $OUT/${PREFIX}-cert.pem ] ; then + if [ -z "$BATCH" ] ; then + echo The files $OUT/${PREFIX}-key.pem and/or $OUT/${PREFIX}-cert.pem already exist! + echo Use -f option to force recreation of keypair. + exit 2 + fi + exit 0 +fi + +if [ -z "$FQDN" ] ; then + FQDN=`hostname` +fi + +if [ -z "$YEARS" ] ; then + YEARS=10 +fi + +DAYS=`expr $YEARS \* 365` + +if [ -z "$ENTITYID" ] ; then + ALTNAME=DNS:$FQDN +else + ALTNAME=DNS:$FQDN,URI:$ENTITYID +fi + +SSLCNF=$OUT/${PREFIX}-cert.cnf +cat >$SSLCNF < /dev/null +fi +rm $SSLCNF + +if [ -s $OUT/${PREFIX}-key.pem -a -n "$USER" ] ; then + chown $USER $OUT/${PREFIX}-key.pem $OUT/${PREFIX}-cert.pem +fi + +if [ -s $OUT/${PREFIX}-key.pem -a -n "$GROUP" ] ; then + chgrp $GROUP $OUT/${PREFIX}-key.pem $OUT/${PREFIX}-cert.pem +fi + diff --git a/container_files/system/startup.sh b/container_files/system/startup.sh new file mode 100755 index 0000000..b5f0d3a --- /dev/null +++ b/container_files/system/startup.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +#for passed-in env vars, remove spaces and replace any ; with : in usertoken env var since we will use ; as a delimiter +export USERTOKEN="${USERTOKEN//;/:}" +export USERTOKEN="${USERTOKEN// /}" +export ENV="${ENV//;/:}" +export ENV="${ENV// /}" + +# generic console logging pipe for anyone +mkfifo -m 666 /tmp/logpipe +cat <> /tmp/logpipe 1>&2 & + +mkfifo -m 666 /tmp/logcrond +(cat <> /tmp/logcrond | awk -v ENV="$ENV" -v UT="$USERTOKEN" '{printf "crond;console;%s;%s;%s\n", ENV, UT, $0; fflush()}' 1>/tmp/logpipe) & + +mkfifo -m 666 /tmp/loghttpd +(cat <> /tmp/loghttpd | awk -v ENV="$ENV" -v UT="$USERTOKEN" '{printf "httpd;console;%s;%s;%s\n", ENV, UT, $0; fflush()}' 1>/tmp/logpipe) & + +mkfifo -m 666 /tmp/logsuperd +(cat <> /tmp/logsuperd | awk -v ENV="$ENV" -v UT="$USERTOKEN" '{printf "supervisord;console;%s;%s;%s\n", ENV, UT, $0; fflush()}' 1>/tmp/logpipe) & + +mkfifo -m 666 /tmp/logshibd +(cat <> /tmp/logshibd | awk -v ENV="$ENV" -v UT="$USERTOKEN" '{printf "shibd;console;%s;%s;%s\n", ENV, UT, $0; fflush()}' 1>/tmp/logpipe) & + +#launch supervisord +/usr/bin/supervisord -c /etc/supervisor/supervisord.conf + diff --git a/container_files/system/supervisord.conf b/container_files/system/supervisord.conf new file mode 100644 index 0000000..952bed5 --- /dev/null +++ b/container_files/system/supervisord.conf @@ -0,0 +1,38 @@ +[supervisord] +logfile=/tmp/logsuperd +logfile_maxbytes=0 +loglevel=error +nodaemon=true +user=root + +[program:cron] +command=/usr/sbin/crond -n +autostart=true +autorestart=true +stdout_logfile=/tmp/logcrond +stdout_logfile_maxbytes=0 +stderr_logfile=/tmp/logcrond +stderr_logfile_maxbytes=0 +directory=/usr/bin + +[program:httpd] +command=httpd -DFOREGROUND +autostart=true +autorestart=true +stdout_logfile=/tmp/loghttpd +stdout_logfile_maxbytes=0 +stderr_logfile=/tmp/loghttpd +stderr_logfile_maxbytes=0 + +[program:shibd] +command=/usr/sbin/shibd -f +autostart=true +autorestart=true +stdout_logfile=/tmp/logshibd +stdout_logfile_maxbytes=0 +stderr_logfile=/tmp/logshibd +stderr_logfile_maxbytes=0 +environment=LD_LIBRARY_PATH=/opt/shibboleth/lib64 + +[include] +files=/etc/supervisor/conf.d/* diff --git a/install.sh b/install.sh deleted file mode 100755 index ddfd5b0..0000000 --- a/install.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -git clone git@github.internet2.edu:docker/util.git -find util/bin -name "*.sh" -exec sh -c 'echo "$1" | sed "s/util\///" >> .gitignore' -- {} \; -mkdir -p bin -mv util/bin/* bin/. -mv util/README.md BINSCRIPTS.md -if [ ! -f common.bash ]; then - mv util/common.bash.sample common.bash -fi -if [ ! -f Jenkinsfile ]; then - mv util/Jenkinsfile.sample Jenkinsfile -fi -rm -rf util diff --git a/tests/clairscan.sh b/tests/clairscan.sh new file mode 100755 index 0000000..a06ea78 --- /dev/null +++ b/tests/clairscan.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +startsecs=$(date +'%s') +starttime=$(date +%H:%M:%S) + +echo 'starting:' ${starttime} + +#ensure clair-scanner +if [ ! -s ./clair-scanner ]; then + echo 'downloading curl-scanner...' + curl -s -L -o ./clair-scanner https://github.com/arminc/clair-scanner/releases/download/v8/clair-scanner_linux_amd64 + chmod 755 clair-scanner +else + echo 'using existing clair-scanner...' +fi + +#ensure DB container +echo 'ensuring a fresh clair-db container...' +docker ps | grep clair-db &>/dev/null +if [ $? == "0" ]; then + echo 'removing existing clair-db container...' + docker kill db &>/dev/null + docker rm db &>/dev/null + docker run -p 5432:5432 -d --name db arminc/clair-db:latest &>/dev/null +else + docker run -p 5432:5432 -d --name db arminc/clair-db:latest &>/dev/null +fi +sleep 30 + +#ensure clair-scan container +echo 'ensuring a fresh clair-scan container...' +docker ps | grep clair-local-scan &>/dev/null +if [ $? == "0" ]; then + echo 'removing existing clair-scan container...' + docker kill clair &>/dev/null + docker rm clair &>/dev/null + docker run -p 6060:6060 --link db:postgres -d --name clair arminc/clair-local-scan:v2.0.5 &>/dev/null +else + docker run -p 6060:6060 --link db:postgres -d --name clair arminc/clair-local-scan:v2.0.5 &>/dev/null +fi +sleep 30 + +#get ip where clair-scanner will listen +clairip=$(/sbin/ifconfig docker0 | grep 'inet ' | sed 's/^[[:space:]]*//g' | cut -f 2 -d ' ' | sed 's/^[[:space:]]*//g') +echo 'sending ip addr' ${clairip} 'to clair-scan server...' + +#run scan +echo 'running scan...' +./clair-scanner --ip ${clairip} $1 +retcode=$? + +#eval results +if [ $retcode == '0' ]; then + echo 'scan found nothing.' +else + echo 'scan found issues.' +fi + +#cleanup +echo 'removing temporary containers...' +docker kill clair &>/dev/null +docker rm clair &>/dev/null +docker kill db &>/dev/null +docker rm db &>/dev/null + +endsecs=$(date +'%s') +endtime=$(date +%H:%M:%S) +echo 'finished:' $endtime ' ('$((endsecs - startsecs)) 'seconds)' +echo "" + +#pass along return code from scan +exit $retcode + diff --git a/tests/image.bats b/tests/image.bats index 769c4c9..792cede 100644 --- a/tests/image.bats +++ b/tests/image.bats @@ -11,17 +11,17 @@ load ../common } @test "Sample attribute map available" { - docker run -i $maintainer/$imagename find /opt/etc/shibboleth/attribute-map.xml + docker run -i $maintainer/$imagename find /etc/shibboleth/attribute-map.xml } @test "Includes InCommon cert" { - docker run -i $maintainer/$imagename find /opt/etc/shibboleth/inc-md-cert.pem + docker run -i $maintainer/$imagename find /etc/shibboleth/inc-md-cert.pem } -@test "Includes Shibboleth keygenerator" { - docker run -i $maintainer/$imagename find /opt/bin/shibboleth_keygen.sh +@test "Includes startup script" { + docker run -i $maintainer/$imagename find /usr/local/bin/startup.sh } -@test "Includes httpd + shibd startup script" { - docker run -i $maintainer/$imagename find /opt/bin/httpd-shib-foreground -} \ No newline at end of file +@test "070 There are no known security vulnerabilities" { + ./tests/clairscan.sh ${maintainer}/${imagename}:latest +} diff --git a/tests/running.bats b/tests/running.bats index 882aaec..781715b 100644 --- a/tests/running.bats +++ b/tests/running.bats @@ -17,4 +17,5 @@ load ../common @test "Exposes running SSO process" { result="$(docker exec -i $imagename curl http://localhost/Shibboleth.sso/Status)" [ "$result" != '' ] -} \ No newline at end of file +} +