Speaking of Spring Boot Java Logging, Some Misadventures

Preface: I set out upon a task to incorporate some masking, redaction, or filtering of some sort on PII (Personally Identifying Information) for the log files and log data an application service is producing. The application pre-exists, so this isn’t entirely a green field situation, but the application generally fits a Spring Boot Service style application. The one key thing I wasn’t sure about when starting, was what kind of logging was already incorporated into the operational service.

Log Masking for Different Logging Libraries

The first solution I came up with was to incorporate a converter or appender of some sort that would mask PII with a string of some sort, like “****” or “—–“. This solution that I came up with, upon checking, looked like it would work out ok with or for a number of the top logging libraries for Java, specially libraries that run with or as a Spring Boot service like LogBack or Log4j.

Continue reading “Speaking of Spring Boot Java Logging, Some Misadventures”

Using Multiple SSH Keys for Multiple Github Account

FIRST – Setup the Keys

If there is already a key, I can use this one to start with, but if there is no key to start with I’ll need to generate one. I can do this with the following command:

ssh-keygen -t rsa

When generating the keys, best to go with the default location, which is ~/.ssh/id_rsa. This will create two files, id_rsa and id_rsa.pub. The id_rsa file is the private key, and the id_rsa.pub file is the public key. The private key should be kept secret, and the public key can be shared with anyone.

For the next account, which I’ll just call the work account, I’ll generate another new key. This time I’ll hand off the following parameters to the key generation to provide the work account email and the file name:

ssh-keygen -t rsa -C "adron.account@work_mail.com" -f "work_account_one"

I’ve now got two keys, one for my personal account and one for my work account.

~/.ssh/id_rsa

~/.ssh/work_account_one

I’ll need to add these to the ssh-agent and the respect Github (or git whatever servers) so that I can use them.

SECOND – Add the Keys to Github

Adding the keys to Github. We’ll start with the personal account and then add the work account. Copy the public key using pbcopy < ~/.ssh/id_rsa.pub. With that copied log into the Github account that this key should be associated with.

1. Got to *settings*.
2. Select *SSH and GPG keys* from the account user menu.
3. Navigate into `New SSH Key`, give it a title, and paste the key into the key field.
4. Click *Add SSH Key*.

Now log out of that Github account and into the other account, the work account. Repeat the steps above, but this time use the work account email and the work account key.

THIRD

Register the new keys with ssh-agent. Start by checking that the ssh-agent is running with eval "$(ssh-agent -s)". In the past we would add the keys to the agent with ssh-add -K ~/.ssh/id_rsa and ssh-add -K ~/.ssh/work_account_one. Now the keys are registered with the agent with the following.

ssh-add --apple-use-keychain ~/.ssh/id_rsa
ssh-add --apple-use-keychain ~/.ssh/work_account_one

FOURTH

There is one last step, I need to tell the ssh client which key to use for which account. I can do this by adding the following to the ~/.ssh/config file.

# Account 1 - Primary
Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa
  AddKeysToAgent yes
  UseKeychain yes

# Account 2 - Second Account
Host github.com-work_user_account_name
  HostName github.com
  User git
  IdentityFile ~/.ssh/work_account_one
  AddKeysToAgent yes
  UseKeychain yes

Note that work_user_account_name is the name of the work account, not the email address. I can now use the following commands to clone repositories from the respective accounts. This tells ssh-agent to use the id_rsa key for Git URLs starting with github.com and the work_account_one key for Git URLs starting with github-work_user_account_name.

FIFTH

One active SSH key per working session.

This is a good practice to follow. I can use the following command to start the ssh-agent and add the key to it.

eval "$(ssh-agent -s) ssh-add -K ~/.ssh/id_rsa ssh-add ~/.ssh/id_rsa

The same can then be done when the other key needs to be used.

Ubuntu on Hyper-V, Insuring Enhanced Session Works

Enhanced session mode provides significantly higher performance, hardware utilization, and things like copy & paste between the host and the VM. To make the best use of the VM as a work station this feature is a must have. However, an Ubuntu (or other) installation doesn’t have this capability provided by default, additional software and steps are required to get it working. Those steps are what follows.

Continue reading “Ubuntu on Hyper-V, Insuring Enhanced Session Works”

An Approach to Learning Java Fast for New & Experienced Polyglot Coders

If you’re just starting out learning Java, here are the top 5 things you can do to get started effectively:

  1. Set Up Your Development Environment:
    • Install the Java Development Kit (JDK) on your computer. You can download it from the official Oracle website or use an open-source distribution like OpenJDK. It can be confusing at first, because there are a bunch of versions you *could* get started with depending on a million different variables, just pick the latest though and get going.
    • Choose a code editor or Integrated Development Environment (IDE) like Eclipse, IntelliJ IDEA, or Visual Studio Code to write and run your Java code. IDEs offer features like code completion and debugging, which can be very helpful for beginners.
  2. Learn the Basics of Java:
    • Start with the fundamental concepts of Java, such as variables, data types, operators, and control structures (if statements, loops).
    • Understand the object-oriented programming (OOP) principles that Java is based on, including classes, objects, inheritance, encapsulation, and polymorphism. Even if you do not use any of these and you’re taking a different approach (functional, top-down, etc) it’s really important to at least learn and understand the OOP concepts and capabilities of Java, as at some point you will see these and to understand what is going on, you’ll need to understand this part of Java.
Continue reading “An Approach to Learning Java Fast for New & Experienced Polyglot Coders”

Building a Container Image w/ jib-maven Build Plugin

First I’ve setup a project, similar to the Hello World GraphQL API I setup here. I’ll setup another project that specifically uses Maven, to use the jib-maven plugin.

Setting Up the Project

I’ve used the standard Spring Initializr in Intellij.

  • Project: Maven Project
  • Language: Java
  • Spring Boot: Choose the latest stable version
  • Project Metadata: Fill in as per your requirement
  • Packaging: Jar
  • Java Version: Choose your Java version (e.g., 11)
  • Dependencies: Add ‘Spring Web’, ‘Spring Boot DevTools’, and ‘Spring for GraphQL’
Continue reading “Building a Container Image w/ jib-maven Build Plugin”