-
Notifications
You must be signed in to change notification settings - Fork 614
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0ee259
commit a64bb8f
Showing
39 changed files
with
1,156 additions
and
405 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
Copyright The containerd Authors. | ||
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 main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/containerd/containerd" | ||
"github.com/containerd/containerd/namespaces" | ||
"github.com/opencontainers/go-digest" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func newClient(clicontext *cli.Context) (*containerd.Client, context.Context, context.CancelFunc, error) { | ||
ctx := context.Background() | ||
namespace := clicontext.String("namespace") | ||
ctx = namespaces.WithNamespace(ctx, namespace) | ||
address := clicontext.String("address") | ||
const dockerContainerdaddress = "\\\\.\\pipe\\containerd-containerd" | ||
//TODO fall back? | ||
client, err := containerd.New(address) | ||
if err != nil { | ||
return nil, nil, nil, err | ||
} | ||
var cancel context.CancelFunc | ||
ctx, cancel = context.WithCancel(ctx) | ||
return client, ctx, cancel, nil | ||
} | ||
|
||
// getDataStore returns a string like "/var/lib/nerdctl/1935db59". | ||
// "1935db9" is from `$(echo -n "/run/containerd/containerd.sock" | sha256sum | cut -c1-8)`` | ||
func getDataStore(clicontext *cli.Context) (string, error) { | ||
dataRoot := clicontext.String("data-root") | ||
if err := os.MkdirAll(dataRoot, 0700); err != nil { | ||
return "", err | ||
} | ||
addrHash, err := getAddrHash(clicontext.String("address")) | ||
if err != nil { | ||
return "", err | ||
} | ||
dataStore := filepath.Join(dataRoot, addrHash) | ||
if err := os.MkdirAll(dataStore, 0700); err != nil { | ||
return "", err | ||
} | ||
return dataStore, nil | ||
} | ||
|
||
func getAddrHash(addr string) (string, error) { | ||
const addrHashLen = 8 | ||
|
||
d := digest.SHA256.FromString(addr) | ||
h := d.Encoded()[0:addrHashLen] | ||
return h, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
Copyright The containerd Authors. | ||
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 main | ||
|
||
import ( | ||
"github.com/containerd/containerd/pkg/cap" | ||
"github.com/opencontainers/runtime-spec/specs-go" | ||
) | ||
|
||
func setCapabilities(pspec *specs.Process) error { | ||
if pspec.Capabilities == nil { | ||
pspec.Capabilities = &specs.LinuxCapabilities{} | ||
} | ||
allCaps, err := cap.Current() | ||
if err != nil { | ||
return err | ||
} | ||
pspec.Capabilities.Bounding = allCaps | ||
pspec.Capabilities.Permitted = pspec.Capabilities.Bounding | ||
pspec.Capabilities.Inheritable = pspec.Capabilities.Bounding | ||
pspec.Capabilities.Effective = pspec.Capabilities.Bounding | ||
|
||
// https://github.com/moby/moby/pull/36466/files | ||
// > `docker exec --privileged` does not currently disable AppArmor | ||
// > profiles. Privileged configuration of the container is inherited | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
Copyright The containerd Authors. | ||
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 main | ||
|
||
import ( | ||
"github.com/opencontainers/runtime-spec/specs-go" | ||
) | ||
|
||
func setCapabilities(pspec *specs.Process) error { | ||
//no op windows | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
Copyright The containerd Authors. | ||
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 main | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
|
||
"github.com/pkg/errors" | ||
"golang.org/x/term" | ||
) | ||
|
||
func readPassword() (string, error) { | ||
var fd int | ||
if term.IsTerminal(syscall.Stdin) { | ||
fd = syscall.Stdin | ||
} else { | ||
tty, err := os.Open("/dev/tty") | ||
if err != nil { | ||
return "", errors.Wrap(err, "error allocating terminal") | ||
} | ||
defer tty.Close() | ||
fd = int(tty.Fd()) | ||
} | ||
bytePassword, err := term.ReadPassword(fd) | ||
if err != nil { | ||
return "", errors.Wrap(err, "error reading password") | ||
} | ||
|
||
return string(bytePassword), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
Copyright The containerd Authors. | ||
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 main | ||
|
||
import ( | ||
"bufio" | ||
"os" | ||
) | ||
|
||
func readPassword() (string, error) { | ||
reader := bufio.NewReader(os.Stdin) | ||
pwd, _ := reader.ReadString('\n') | ||
|
||
return pwd, nil | ||
} |
Oops, something went wrong.