mirror of
https://github.com/gravitational/teleport.git
synced 2026-11-02 14:59:53 +08:00
In the context of Teleport Discover we are trying to ease the usage of Teleport for the user's first interaction. When adding a new database resource the user must, among other things, generate the mTLS files Examples: https://goteleport.com/docs/database-access/guides/postgres-self-hosted/#step-25-create-a-certificatekey-pair https://goteleport.com/docs/database-access/guides/mysql-self-hosted/#step-24-create-a-certificatekey-pair This PR aims to reduce this friction: the user should be able to setup the resource without prior setup of local tools (`tsh login`) We're doing this by providing an endpoint that will return those exact files Demo ```shell marco@lenix ~/p/downloadmtls> curl --silent --insecure 'https://127.0.0.1.nip.io:3080/v1/webapi/sites/lenix/sign' --dat a '{"hostname":"discover.example.com", "ttl":"9999h", "format": "db"}' --header 'Authorization: Bearer 308bf3dd3019ddc4 2cff44a48e028480' --header 'Content-Type: application/json' -OJ marco@lenix ~/p/downloadmtls> tar -xvf teleport_mTLS_discover.example.com.tar.gz server.key server.crt server.cas marco@lenix ~/p/downloadmtls> head -1 server.* ==> server.cas <== -----BEGIN CERTIFICATE----- ==> server.crt <== -----BEGIN CERTIFICATE----- ==> server.key <== -----BEGIN RSA PRIVATE KEY----- ``` Fixes https://github.com/gravitational/teleport/issues/14049
79 lines
1.8 KiB
Go
79 lines
1.8 KiB
Go
/*
|
|
Copyright 2022 Gravitational, Inc.
|
|
|
|
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 utils
|
|
|
|
import (
|
|
"io/fs"
|
|
"time"
|
|
)
|
|
|
|
// InMemoryFile stores the required properties to emulate a File in memory
|
|
// It contains the File properties like name, size, mode
|
|
// It also contains the File contents
|
|
// It does not support folders
|
|
type InMemoryFile struct {
|
|
name string
|
|
mode fs.FileMode
|
|
modTime time.Time
|
|
content []byte
|
|
}
|
|
|
|
func NewInMemoryFile(name string, mode fs.FileMode, modTime time.Time, content []byte) *InMemoryFile {
|
|
return &InMemoryFile{
|
|
name: name,
|
|
mode: mode,
|
|
modTime: modTime,
|
|
content: content,
|
|
}
|
|
}
|
|
|
|
// Name returns the file's name
|
|
func (fi *InMemoryFile) Name() string {
|
|
return fi.name
|
|
}
|
|
|
|
// Size returns the file size (calculated when writing the file)
|
|
func (fi *InMemoryFile) Size() int64 {
|
|
return int64(len(fi.content))
|
|
}
|
|
|
|
// Mode returns the fs.FileMode
|
|
func (fi *InMemoryFile) Mode() fs.FileMode {
|
|
return fi.mode
|
|
}
|
|
|
|
// ModTime returns the last modification time
|
|
func (fi *InMemoryFile) ModTime() time.Time {
|
|
return fi.modTime
|
|
}
|
|
|
|
// IsDir checks whether the file is a directory
|
|
func (fi *InMemoryFile) IsDir() bool {
|
|
return false
|
|
}
|
|
|
|
// Sys is platform independent
|
|
// InMemoryFile's implementation is no-op
|
|
func (fi *InMemoryFile) Sys() interface{} {
|
|
return nil
|
|
}
|
|
|
|
// Content returns the file bytes
|
|
func (fi *InMemoryFile) Content() []byte {
|
|
return fi.content
|
|
}
|