The problem: osbuild-composer used to have a rather uncomplete logic for selecting client certificates and keys while fetching data from repositories that use the "subscription model". In this scenario, every repo requires the user to use a client-side TLS certificate. The problem is that every repo can use its own CA and require a different pair of a certificate and a key. This case wasn't handled at all in composer. Furthermore, osbuild-composer can use remote workers which complicates things even more. Assumptions: The problem outlined above is hard to solve in the general case, but Red Hat Subscription Manager places certain limitations on how subscriptions might be used. For example, a subscription must be tight to a host system, so there is no way to use such a repository in osbuild-composer without it being available on the host system as well. Also, if a user wishes to use a certain repository in osbuild-composer it must be available on both hosts: the composer and the worker. It will come with different pair of a client certificate and a key but otherwise, its configuration remains the same. The solution: Expect all the subscriptions to be registered in the /etc/yum.repos.d/redhat.repo file. Read the mapping of URLs to certificates and keys from there and use it. Don't change the manifest format and let osbuild guess the appropriate subscription to use.
49 lines
1.6 KiB
Go
49 lines
1.6 KiB
Go
package rhsm
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
var VALID_REPO = `[jws]
|
|
name = Red Hat JBoss Web Server
|
|
baseurl = https://cdn.redhat.com/content/dist/middleware/jws/1.0/$basearch/os
|
|
enabled = 0
|
|
gpgcheck = 1
|
|
gpgkey = file://
|
|
sslverify = 1
|
|
sslcacert = /etc/rhsm/ca/redhat-uep.pem
|
|
sslclientkey = /etc/pki/entitlement/123-key.pem
|
|
sslclientcert = /etc/pki/entitlement/456.pem
|
|
metadata_expire = 86400
|
|
enabled_metadata = 0
|
|
|
|
[rhel-atomic]
|
|
name = Red Hat Container Development Kit
|
|
baseurl = https://cdn.redhat.com/content/dist/rhel/atomic/7/7Server/$basearch/os
|
|
enabled = 0
|
|
gpgcheck = 1
|
|
gpgkey = http://
|
|
sslverify = 1
|
|
sslcacert = /etc/rhsm/ca/redhat-uep.pem
|
|
sslclientkey = /etc/pki/entitlement/789-key.pem
|
|
sslclientcert = /etc/pki/entitlement/101112.pem
|
|
metadata_expire = 86400
|
|
enabled_metadata = 0
|
|
`
|
|
|
|
func TestParseRepoFile(t *testing.T) {
|
|
input := []byte(VALID_REPO)
|
|
repoFileContent, err := parseRepoFile(input)
|
|
require.NoError(t, err, "Failed to parse the .repo file")
|
|
subscriptions := Subscriptions{
|
|
available: repoFileContent,
|
|
}
|
|
secrets, err := subscriptions.GetSecretsForBaseurl("https://cdn.redhat.com/content/dist/middleware/jws/1.0/x86_64/os", "x86_64", "")
|
|
require.NoError(t, err, "Failed to get secrets for a baseurl")
|
|
assert.Equal(t, secrets.SSLCACert, "/etc/rhsm/ca/redhat-uep.pem", "Unexpected path to the CA certificate")
|
|
assert.Equal(t, secrets.SSLClientCert, "/etc/pki/entitlement/456.pem", "Unexpected path to the client cert")
|
|
assert.Equal(t, secrets.SSLClientKey, "/etc/pki/entitlement/123-key.pem", "Unexpected path to the client key")
|
|
}
|