Log In to Aiven with FusionAuth over SAML v2

On this page

Aiven is a cloud data platform. Aiven supports single sign-on with SAML v2 identity providers. With FusionAuth as the identity provider, users log in to Aiven with their FusionAuth accounts. For the general steps for any external application, see Add Login to an External App.

Before You Begin#

You need:

  • An Aiven organization, an Aiven user with the role:organization:admin permission, and a verified domain in the organization.
  • Admin access to FusionAuth.
  • A FusionAuth URL that your users' browsers can reach.
  • A test user in the TenantA logical container for Users, Applications, and settings that is isolated from other Tenants. you plan to use.
  • bash, openssl, jq, and curl on the computer where you create the certificate.

Start Adding FusionAuth in Aiven#

Aiven gives you the URLs that FusionAuth needs. To get the URLs:

  1. In the Aiven Console, open your organization and click Admin -> Identity providers .
  2. Click Add identity provider .
  3. Select FusionAuth and enter a name, such as FusionAuth.
  4. Select the verified domain to link to the identity provider.
  5. Copy the Metadata URL and the ACS URL. Leave the Aiven page open.

Create a Signing Certificate#

Aiven doesn't accept the X.509 version 2 certificates that Key MasterThe FusionAuth subsystem for managing cryptographic keys. generates. Create an X.509 v3 certificate outside FusionAuth, and import the certificate into Key Master with the certificate's private key. A script does both. The script calls the Keys API, so the script needs an API key first.

  1. In FusionAuth, navigate to Settings -> API Keys and click .

  2. Set Name to Certificate generator.

  3. In the Endpoints list, find /api/key/import and enable POST .

    The Add API Key form, with POST enabled for the key import endpoint.
    The Add API Key form, with POST enabled for the key import endpoint.
  4. Click .

  5. On the API Keys page, click the value in the Key column of the new API key, and copy the value.

  6. Save the following script as generate-certificate:

    #!/bin/bash
    
    # Checking openssl
    if [[ -z $(which openssl) ]]; then
      echo "Please download openssl and make sure it is available in your PATH variable"
      echo "Homepage: https://www.openssl.org/"
      exit 1
    fi
    
    # Checking jq
    if [[ -z $(which jq) ]]; then
      echo "Please download jq and make sure it is available in your PATH variable"
      echo "jq is used to parse JSON elements"
      echo "Homepage: https://stedolan.github.io/jq/"
      exit 1
    fi
    
    # FusionAuth URL
    read -r -p "Your FusionAuth instance URL (with scheme): " FA_URL
    regex='^https?:\/\/[^\/]+(:[0-9]+\/)?$'
    if ! [[ $FA_URL =~ $regex ]]; then
      echo "FusionAuth URL is not valid. Please make sure you have included the scheme (http:// or https://)."
      exit 2
    fi
    
    # Extracting domain from URL
    FA_DOMAIN=$(echo "$FA_URL" | awk -F/ '{print $3}')
    if [[ -z "$FA_DOMAIN" ]]; then
      echo "FusionAuth URL is not valid. Please make sure you have included the scheme (http:// or https://)."
      exit 2
    fi
    
    # FusionAuth API Key
    read -r -p "API Key with /api/key/import endpoint:      " API_KEY
    if [[ -z "$API_KEY" ]]; then
      echo "Please provide an API Key."
      exit 2
    fi
    
    # Key name
    read -r -p "Name for the generated key:                 " NAME
    if [[ -z "$NAME" ]]; then
      echo "Please provide a valid name for the key."
      exit 2
    fi
    
    # Creating temporary files for public and private keys
    PRIVATE_KEY_FILE=$(mktemp)
    if [[ -z "$PRIVATE_KEY_FILE" ]]; then
      echo "Cannot create private key. Please make sure your temporary directory is writable."
      exit 3
    fi
    CERTIFICATE_FILE=""
    cleanup() {
      if [[ -n "$PRIVATE_KEY_FILE" ]]; then
        rm -f "$PRIVATE_KEY_FILE"
      fi
      if [[ -n "$CERTIFICATE_FILE" ]]; then
        rm -f "$CERTIFICATE_FILE"
      fi
    }
    trap cleanup EXIT
    CERTIFICATE_FILE=$(mktemp)
    if [[ -z "$CERTIFICATE_FILE" ]]; then
      echo "Cannot create certificate. Please make sure your temporary directory is writable."
      exit 3
    fi
    
    # Creating certificate
    RSA_LENGTH=2048
    echo "Generating certificate..."
    if ! openssl req -x509 -newkey "rsa:$RSA_LENGTH" -nodes -keyout "$PRIVATE_KEY_FILE" -out "$CERTIFICATE_FILE" -sha256 -days 3650 -subj "/CN=$FA_DOMAIN/"; then
      echo "Error generating certificate. Check messages above for more details."
      exit 4
    fi
    CERTIFICATE=$(cat "$CERTIFICATE_FILE")
    PRIVATE_KEY=$(cat "$PRIVATE_KEY_FILE")
    
    # shellcheck disable=SC2016
    JSON_TEMPLATE='{
      "key": {
        "algorithm": "RS256",
        "name": $name,
        "certificate": $certificate,
        "privateKey": $privateKey,
        "length": $rsaLength
      }
    }'
    
    # Uploading keys to the key master
    echo "Uploading to the Key Master..."
    JSON=$(jq --null-input \
      --arg name "$NAME" \
      --arg certificate "$CERTIFICATE" \
      --arg privateKey "$PRIVATE_KEY" \
      --arg rsaLength "$RSA_LENGTH" \
      "$JSON_TEMPLATE")
    if ! curl --fail-with-body -s -o /dev/null \
      -d "$JSON" \
      -H "Authorization: $API_KEY" \
      -H "Content-type: application/json" \
      "$FA_URL/api/key/import"; then
      echo "Error uploading certificate to the Key Master. Check messages above for more details."
      exit 5
    fi
    
    echo "Successfully uploaded key to the Key Master."
    echo "Here is the generated certificate:"
    echo "$CERTIFICATE"
  7. Run the script:

    $ bash generate-certificate
    
  8. Enter the FusionAuth URL, the API key, and a name for the key, such as Aiven key:

    Example answers to the script prompts
    Your FusionAuth instance URL (with scheme): https://auth.example.com
    API Key with /api/key/import endpoint:      <your API key>
    Name for the generated key:                 Aiven key
    
  9. Copy the certificate that the script prints, from -----BEGIN CERTIFICATE----- through -----END CERTIFICATE-----.

The script creates a certificate that is valid for 10 years. When you finish, delete the Certificate generator API key.

Create the Application#

Aiven needs its own ApplicationA software program that your users log in to through FusionAuth. in FusionAuth. To create the Application:

  1. Navigate to Applications and click .
  2. Set Name to Aiven, and select the Tenant that holds your users.
  3. Select the SAML tab and enable Enable SAML v2.
  4. Set Issuer to the Metadata URL from Aiven.
  5. Add the ACS URL from Aiven to Authorized redirect URLs.
  6. In the Authentication response section, set Signing key to the key that the script created, such as Aiven key.
  7. Click .
  8. On the Applications page, open the action menu for the Application and select View .
  9. In the SAML v2 Integration details section, copy the Entity Id and the Login URL.

Finish the Configuration in Aiven#

To connect Aiven to FusionAuth:

  1. On the Aiven page, set IDP URL to the Login URL from FusionAuth.
  2. Set Entity ID to the Entity Id from FusionAuth.
  3. Paste the certificate from the script into Certificate, and click Next .
  4. Choose the security options, and click Next . For a description of each option, see Add SAML identity providers in the Aiven documentation.
  5. When all users who sign up with FusionAuth belong in one Aiven group, select the group.
  6. Click Finish .
  7. Copy the Signup URL. Users without an Aiven account use the Signup URL to create an Aiven account that logs in with FusionAuth. Users with an Aiven account use the User account link URL instead.

Give Users Access#

Any user in the Tenant can log in to Aiven by default. To limit login to users with a RegistrationThe association between a User and an Application. for the Application, enable Require registration to complete OAuth authorization on the OAuth tab of the Application. The setting applies to SAML v2 logins too. For more information, see Registrations.

Confirm the Login#

To confirm that login works:

  1. Open the Signup URL in a private browser window.
  2. Start the login with FusionAuth from the Aiven page.
  3. Confirm that the browser shows the FusionAuth login page.
  4. Log in as the test user.
  5. Confirm that the browser returns to the Aiven Console and that the test user is logged in.

When the login fails, enable Enable debug logging on the SAML tab of the Application and try again. Read the details in System -> Event Log . Turn off debug logging when you finish.