Bridging the Divide: Setting Up Secure SSH Connections for Mainframe-GitHub/GitLab Integration

SSH Connection Setup for GitHub and GitLab Integration with Mainframes

The venerable mainframe, once synonymous with monolithic applications and glacial development cycles, is experiencing a renaissance. This shift is fueled by the embrace of modern DevOps practices, propelling the mainframe into the vibrant realm of continuous integration, continuous delivery (CI/CD), and collaborative development. But bridging the gap between the mainframe and popular distributed version control systems (DVCS) like GitHub and GitLab can feel like traversing a chasm. Fear not, intrepid developers! Secure SSH connections come to the rescue, paving the way for seamless integration and unleashing the power of DevOps workflows for your mainframe projects.

This guide serves as your trusty map, navigating you through the intricacies of establishing secure SSH connections between your mainframe and GitHub/GitLab. We’ll equip you with the knowledge and practical steps to confidently bridge the divide, transforming your mainframe from a solitary island into a thriving hub of collaborative development.

Why SSH for Mainframe-GitHub/GitLab Integration?

While protocols like HTTP/HTTPS offer basic connectivity, SSH (Secure Shell) reigns supreme for its robust security features. Imagine it as a fortified tunnel, encrypting all communication between your mainframe and GitHub/GitLab, shielding sensitive data like commit histories and credentials from prying eyes. Beyond its impenetrable armor, SSH provides:

  • Authentication: Employ strong login mechanisms like password authentication or public-key cryptography to ensure only authorized users access your precious codebase.
  • Flexibility: SSH acts as a versatile Swiss Army knife, empowering you to run commands, transfer files, and automate tasks, essential for scripting CI/CD pipelines.
  • Granular Control: Define who can do what with access control configurations, ensuring your codebase remains safe from accidental or malicious modifications.

Generating SSH Keys: Your Digital Passports

The foundation of secure connections lies in generating and managing SSH key pairs. Think of these as digital passports, granting access to your Git repository:

  • Private Key: This confidential key resides on your mainframe, acting like a hidden signature, authenticating your identity. Keep it under lock and key, preferably secured with a strong passphrase.
  • Public Key: This public key, akin to a shared visa, is uploaded to GitHub/GitLab, allowing your mainframe to connect without requiring a password.

Commanding the Keys: Tools for Different Realms

The battlefield for generating these keys depends on your chosen weaponry:

  • On your mainframe: Utilize powerful tools like BPlex’s bpkey command or ISPF templates to forge your digital passports.
  • On your local machine (OpenSSH): For those venturing into the realm of OpenSSH, unleash the ssh-keygen command to craft your key pair within the familiar confines of your local terminal.

Example: Forging Your Credentials with BPlex (Mainframe)

Imba
ISPFTEMPLATE ISPFKEY
   EXEC CMD('BPKEY -P 4096')
ENDISPFTEMPLATE

RUN ISPFKEY

bpkey -pubout <private_key_file> > public_key.txt

This ISPF template invokes the bpkey command to generate a key pair and extracts the public key for upload to GitHub/GitLab.

Example: Crafting Your Keys with OpenSSH (Local Machine)

SSH Config
ssh-keygen -t rsa -b 4096 -N "" -f ~/.ssh/id_rsa

This command generates a key pair within the ~/.ssh directory of your local machine, securing your private key with a passphrase.

Uploading the Public Key: Granting Access to Your Git Fortress

With your public key forged, it’s time to grant your mainframe access to your Git repository. Navigate to your user settings on GitHub/GitLab and locate the “SSH and GPG keys” section. Paste the contents of your public key file (e.g., public_key.txt) and give it a descriptive title. Now, your mainframe has the green light to enter the Git fortress.

Connecting to GitHub/GitLab: The Bridge Opens

With your digital credentials in place, let’s build the bridge! Tools like zSecure Secure Shell, OpenSSH with additional configurations, and custom scripts offer powerful avenues for connection.

Example: Crossing the Divide with zSecure Secure Shell (Mainframe)

SSH Config
zsecure sh my-github-server.com -l mainframe_user

# Enter passphrase for your private key

# Run commands on GitHub/GitLab remotely...

This command establishes a secure connection to your Git repository using zSecure Secure Shell, prompting you for your private key passphrase before granting access.

Beyond Basic Connections: The DevOps Revolution Arrives

The power of SSH transcends mere connections. You can leverage it for advanced DevOps tasks like:

  • Automated CI/CD Pipelines: Imagine your code seamlessly triggering builds, tests, and deployments on GitHub/GitLab the moment it touches your mainframe repository. SSH bridges the gap, enabling automated workflows that accelerate application delivery like never before.
  • Jenkins Orchestration: Integrate Jenkins, a popular CI/CD tool, with your SSH connection to orchestrate automated builds and testing on your mainframe. Jenkins pulls code changes from your Git repository, triggers builds using SSH commands, and executes pre-defined tests, ensuring quality and stability before deployment.
  • Remote Script Execution: Unleash the power of automation! Run custom scripts and utilities directly from GitHub/GitLab actions on your mainframe via SSH. Imagine data migration scripts, configuration management tools, or even automated security scans, all orchestrated remotely through secure connections.
  • Enhanced Collaboration and Visibility: Centralize your code in GitHub/GitLab, breaking down the silos between mainframe and non-mainframe developers. Version history, branching, and merge requests provide comprehensive visibility into code changes, fostering clearer communication and better understanding across teams.

Examples in Action: Putting Theory into Practice

Let’s delve deeper into concrete examples:

1. Triggering a z/OS Build from GitHub Actions:

YAML

YAML
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Setup SSH connection
        run: |
          ssh-keygen -t rsa -b 4096 -N "" -f $HOME/.ssh/id_rsa
          # Upload public key to GitHub
          cat $HOME/.ssh/id_rsa.pub > key.pub
          git config user.email "your_email@example.com"
          git config user.name "your_username"
          git add key.pub
          git commit -m "Add SSH public key"
          git push origin HEAD
       - name: Trigger z/OS build
         run: |
           ssh mainframe_user@zOS_server -p 22 <<EOF
             cd /your/project/directory
             ./build_script.sh
           EOF

Use code with caution. Learn morecontent_copy

This workflow generates an SSH key pair, uploads the public key to GitHub, and then connects to the z/OS server via SSH to execute the build_script.sh, triggering the build process automatically.

2. Running Data Migration Script from GitLab:

YAML

YAML
stages:
  - migrate

migrate:
  script:
    - ssh-agent sh -c '
         ssh-add $HOME/.ssh/id_rsa;
         cd /data/migration/scripts;
         ./migrate_data.sh'

Use code with caution. Learn morecontent_copy

This pipeline utilizes a pre-existing SSH key stored in $HOME/.ssh/id_rsa to connect to the mainframe and execute the migrate_data.sh script directly from GitLab, automating the data migration process.

Remember: These are just examples, and your specific workflow configuration will depend on your chosen tools, scripts, and build environments.

Taming the Complexity: A Secure Journey

Embracing SSH connections for Git integration opens exciting possibilities, but complexity and potential risks deserve attention:

  • Security Vigilance: Implement robust security practices like strong passwords, key management, and access control to ensure secure connections and prevent unauthorized access.
  • Audit Logs and Monitoring: Regularly monitor SSH activity and audit logs to identify any suspicious behavior or malicious attempts.
  • Documentation and Training: Provide clear documentation and training for developers on securely using SSH connections and adhering to best practices.

 

 

A Bright Future for Mainframe DevOps:

By embracing secure SSH connections and integrating with platforms like GitHub and GitLab, we are rewriting the narrative of mainframe development. This fusion of modern practices with the stability and power of the mainframe unlocks an unprecedented level of agility, collaboration, and innovation. So, take the leap, secure your connections, and let your mainframe join the DevOps revolution!

Additional Resources:

Sources

info

  1. github.com/AdelinFnk/portfolio