Cockpit/Apache Reverse Proxy Setup

March 14, 2022 - Reading time: ~1 minute

I had a hard time finding the information I needed to get Cockpit to work right behind an Apache reverse proxy setup. So, I decided to collect everything I found here for the future.

At first, I tried to setup cockpit under the /cockpit path but it kept failing. Apparently, that path is reserved by Cockpit, so I switched to using /ckpt/ instead.

  1. Create config file: /etc/cockpit/cockpit.conf
  2. Add contents:
    [WebService]
    Origins = https://mydomain.com http://127.0.0.1:9090
    ProtocolHeader = X-Forwarded-Proto
    AllowUnencrypted = true
    UrlRoot = /ckpt/
  3. Restart Cockpit
  4. Add Apache directives to chosen VirtualHost:
    ProxyPreserveHost On
    ProxyRequests Off
    SSLProxyVerify None
    SSLProxyCheckPeerCN Off
    SSLProxyCheckPeerName Off
    SSLProxyCheckPeerExpire Off
    RewriteEngine On
    RewriteCond %{HTTP:Upgrade} =websocket [NC]
    RewriteRule /ckpt/(.*) ws://127.0.0.1:9090/ckpt/$1 [P,L]
    RewriteCond %{HTTP:Upgrade} !=websocket [NC]
    RewriteRule /ckpt/(.*) http://127.0.0.1:9090/ckpt/$1 [P,L]
    ProxyPass /ckpt/ http://127.0.0.1:9090/ckpt/
    ProxyPassReverse /ckpt/ http://127.0.0.1:9090/ckpt/
  5. Restart Apache

rsync for Windows

February 15, 2022 - Reading time: ~1 minute

I was looking for something like rsync that I can use on Windows. I know that I could install many of the Linux utilities on Windows but I just wanted to see if there was something built-in. Well...robocopy!

robocopy source_dir z:\backup\dest_dir /MIR

The /MIR mirrors the entire directory tree. I'm tempted to say that I actually like it just as much as, or maybe more than, rsync.


SSH escape sequences

February 3, 2022 - Reading time: ~1 minute

Supported escape sequences:

  • ~. - terminate session
  • ~B - send a BREAK to the remote system
  • ~R - Request rekey (SSH protocol 2 only)
  • ~# - list forwarded connections
  • ~? - this message
  • ~~ - send the escape character by typing it twice

(Note that escapes are only recognized immediately after newline.)


SSH ProxyCommand for jumping servers

January 24, 2022 - Reading time: ~1 minute
                                         +--+
                                         |  |
                                         |  |            +--------------------------+
+--------------------------+             |  |            |                          |
|                          |             |  |            |                          |
|                          |       +-----+--+-----+      |                          |
|                          |       |              |      |   Remote Machine (C)     |
|  Local Machine (A)       |       |              |      |                          |
|                          |       |              |      |                          |
|                          |       | Jump Server  |      |                          |
|                          |       |              |      |                          |
|                          |       |     (B)      |      |                          |
|                          |       |              |      |                          |
|                          |       |              |      |                          |
|                          |       |              |      |                          |
|                          |       |              |      +--------------------------+
+--------------------------+       |              |
                                   +-----+--+-----+
                                         |  |
                                         |  |
                                         |  |
                                         +--+

Getting to a server behind a firewall

Machine A can get to Machine B

Machine B can get to Machine C

Machine A CAN NOT get to Machine C directly.

Most people will use SSH to connect from Machine A to Machine B, then use SSH again to connect from Machine B to Machine C.

Another option: ProxyCommand

Add the following to SSH config

Host hostb
    User myself
    Hostname machineB

Host hostc
    User myself
    Hostname machineC
    Port 22
    ProxyCommand ssh -q -W %h:%p hostb

With this configuration, SSH can be used to connect directly from Machine A to Machine C. SSH will automatically direct the connection through Machine B.


ctags for Scala

January 12, 2022 - Reading time: ~1 minute

I looked around for help on creating an options file for ctags to work with Scala code. Keeping it here for easy access.

Options file

--langdef=scala
--langmap=scala:.scala
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private[^ ]*|protected)?[ \t]*class[ \t]+([a-zA-Z0-9_]+)/\4/c,classes/
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private[^ ]*|protected)?[ \t]*object[ \t]+([a-zA-Z0-9_]+)/\4/c,objects/
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private[^ ]*|protected)?[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*case class[ \t]+([a-zA-Z0-9_]+)/\6/c,case classes/
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private[^ ]*|protected)?[ \t]*case object[ \t]+([a-zA-Z0-9_]+)/\4/c,case objects/
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private[^ ]*|protected)?[ \t]*trait[ \t]+([a-zA-Z0-9_]+)/\4/t,traits/
--regex-scala=/^[ \t]*type[ \t]+([a-zA-Z0-9_]+)/\1/T,types/
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy|private[^ ]*(\[[a-z]*\])*|protected)[ \t]*)*def[ \t]+([a-zA-Z0-9_]+)/\4/m,methods/
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy|private[^ ]*|protected)[ \t]*)*val[ \t]+([a-zA-Z0-9_]+)/\3/l,constants/
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy|private[^ ]*|protected)[ \t]*)*var[ \t]+([a-zA-Z0-9_]+)/\3/l,variables/
--regex-scala=/^[ \t]*package[ \t]+([a-zA-Z0-9_.]+)/\1/p,packages/

Using the file

Use the file by passing it to ctags

Example

ctags --options=ctags_scala --exclude=target --exclude=java-ipv6-master --exclude=tests --exclude=testdata --exclude=Session.vim -R .

Script to fix git commit author and email

January 8, 2022 - Reading time: ~1 minute

I don't remember where I found this but it's quite useful.

#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="your-old-email@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your-correct-email@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_COMMITTER_NAME="$CORRECT_NAME"
    export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_AUTHOR_NAME="$CORRECT_NAME"
    export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags

Categories