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.
76 lines
1.9 KiB
Go
76 lines
1.9 KiB
Go
// Copyright 2019 Unknwon
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
|
// not use this file except in compliance with the License. You may obtain
|
|
// a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
// License for the specific language governing permissions and limitations
|
|
// under the License.
|
|
|
|
package ini
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"io"
|
|
"io/ioutil"
|
|
"os"
|
|
)
|
|
|
|
var (
|
|
_ dataSource = (*sourceFile)(nil)
|
|
_ dataSource = (*sourceData)(nil)
|
|
_ dataSource = (*sourceReadCloser)(nil)
|
|
)
|
|
|
|
// dataSource is an interface that returns object which can be read and closed.
|
|
type dataSource interface {
|
|
ReadCloser() (io.ReadCloser, error)
|
|
}
|
|
|
|
// sourceFile represents an object that contains content on the local file system.
|
|
type sourceFile struct {
|
|
name string
|
|
}
|
|
|
|
func (s sourceFile) ReadCloser() (_ io.ReadCloser, err error) {
|
|
return os.Open(s.name)
|
|
}
|
|
|
|
// sourceData represents an object that contains content in memory.
|
|
type sourceData struct {
|
|
data []byte
|
|
}
|
|
|
|
func (s *sourceData) ReadCloser() (io.ReadCloser, error) {
|
|
return ioutil.NopCloser(bytes.NewReader(s.data)), nil
|
|
}
|
|
|
|
// sourceReadCloser represents an input stream with Close method.
|
|
type sourceReadCloser struct {
|
|
reader io.ReadCloser
|
|
}
|
|
|
|
func (s *sourceReadCloser) ReadCloser() (io.ReadCloser, error) {
|
|
return s.reader, nil
|
|
}
|
|
|
|
func parseDataSource(source interface{}) (dataSource, error) {
|
|
switch s := source.(type) {
|
|
case string:
|
|
return sourceFile{s}, nil
|
|
case []byte:
|
|
return &sourceData{s}, nil
|
|
case io.ReadCloser:
|
|
return &sourceReadCloser{s}, nil
|
|
case io.Reader:
|
|
return &sourceReadCloser{ioutil.NopCloser(s)}, nil
|
|
default:
|
|
return nil, fmt.Errorf("error parsing data source: unknown type %q", s)
|
|
}
|
|
}
|