Skip to content

Commit

Permalink
renamed to published ports
Browse files Browse the repository at this point in the history
  • Loading branch information
hellt committed Feb 16, 2021
1 parent d31229c commit 6b9aefd
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 36 deletions.
20 changes: 10 additions & 10 deletions clab/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type NodeConfig struct {
Ports []string `yaml:"ports,omitempty"` // list of port bindings
MgmtIPv4 string `yaml:"mgmt_ipv4,omitempty"` // user-defined IPv4 address in the management network
MgmtIPv6 string `yaml:"mgmt_ipv6,omitempty"` // user-defined IPv6 address in the management network
Share []string `yaml:"share,omitempty"` // list of ports to share with mysocketctl
Publish []string `yaml:"publish,omitempty"` // list of ports to publish with mysocketctl

Env map[string]string `yaml:"env,omitempty"` // environment variables
User string `yaml:"user,omitempty"` // linux user used in a container
Expand Down Expand Up @@ -130,7 +130,7 @@ type Node struct {
TLSKey string
TLSAnchor string
NSPath string // network namespace path for this node
Share []string //list of ports to share with mysocketctl
Publish []string //list of ports to publish with mysocketctl
}

// Link is a struct that contains the information of a link between 2 containers
Expand Down Expand Up @@ -374,14 +374,14 @@ func (c *CLab) userInit(nodeCfg *NodeConfig, kind string) string {
return ""
}

func (c *CLab) shareInit(nodeCfg *NodeConfig, kind string) []string {
func (c *CLab) publishInit(nodeCfg *NodeConfig, kind string) []string {
switch {
case len(nodeCfg.Share) != 0:
return nodeCfg.Share
case len(c.Config.Topology.Kinds[kind].Share) != 0:
return c.Config.Topology.Kinds[kind].Share
case len(c.Config.Topology.Defaults.Share) != 0:
return c.Config.Topology.Defaults.Share
case len(nodeCfg.Publish) != 0:
return nodeCfg.Publish
case len(c.Config.Topology.Kinds[kind].Publish) != 0:
return c.Config.Topology.Kinds[kind].Publish
case len(c.Config.Topology.Defaults.Publish) != 0:
return c.Config.Topology.Defaults.Publish
}
return nil
}
Expand Down Expand Up @@ -424,7 +424,7 @@ func (c *CLab) NewNode(nodeName string, nodeCfg NodeConfig, idx int) error {

user := c.userInit(&nodeCfg, node.Kind)

node.Share = c.shareInit(&nodeCfg, node.Kind)
node.Publish = c.publishInit(&nodeCfg, node.Kind)

switch node.Kind {
case "ceos":
Expand Down
6 changes: 3 additions & 3 deletions clab/mysocketio.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ func createMysocketTunnels(ctx context.Context, c *CLab, node *Node) error {
}

for _, n := range c.Nodes {
if len(n.Share) == 0 {
if len(n.Publish) == 0 {
continue
}
for _, socket := range n.Share {
for _, socket := range n.Publish {
split := strings.Split(socket, "/")
if len(split) > 2 {
log.Warnf("wrong mysocketio share definition %s. should be type/port-number, i.e. tcp/22", socket)
log.Warnf("wrong mysocketio publish section %s. should be type/port-number, i.e. tcp/22", socket)
}
t := split[0] // type
p := split[1] // port
Expand Down
4 changes: 2 additions & 2 deletions cmd/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func toTableData(det []containerDetails) [][]string {

func printContainerInspect(c *clab.CLab, containers []types.Container, bridgeName string, format string) {
contDetails := make([]containerDetails, 0, len(containers))
// do not print shared sockets unless mysocketio kind is found
// do not print published ports unless mysocketio kind is found
printMysocket := false
var mysocketCID string

Expand Down Expand Up @@ -190,7 +190,7 @@ func printContainerInspect(c *clab.CLab, containers []types.Container, bridgeNam
if len(stderr) > 0 {
log.Infof("errors during listing mysocketio sockets: %s", string(stderr))
}
fmt.Println("Shared sockets:")
fmt.Println("Published ports:")
fmt.Println(string(stdout))
}

Expand Down
40 changes: 20 additions & 20 deletions docs/manual/shared-sockets.md → docs/manual/published-ports.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Containerlab labs are typically deployed in the isolated environments, such as company's internal network, cloud instance or even a laptop. The nodes deployed in a lab can happily talk to each other and, if needed, can reach Internet in the outbound direction.

But sometimes it is really needed to let your lab nodes be reachable over Internet securely and privately in the incoming direction. There are many use cases that warrant such _exposure_, some of the most notable are:
But sometimes it is really needed to let your lab nodes be reachable over Internet securely and privately in the incoming direction. There are many use cases that warrant such _publishing_, some of the most notable are:

* create a lab in your environment and share it with a customer/colleague on-demand in no time
* make an interactive demo/training where certain nodes' are shared with an audience for hand-on experience
* share a private lab with someone to collaborate
* expose management interfaces (gNMI, NETCONF, SNMP) to test integration with collectors deployed outside of your lab environment

Containerlab made all of these use cases possible by integrating with [mysocket.io](https://mysocket.io) service. Mysocket.io provides personal tunnels for https/https/tls/tcp sockets over global anycast[^1] network spanning US, Europe and Asia.
Containerlab made all of these use cases possible by integrating with [mysocket.io](https://mysocket.io) service. Mysocket.io provides personal tunnels for https/https/tls/tcp ports over global anycast[^1] network spanning US, Europe and Asia.

To make a certain port of a certain node available via mysocket.io tunnel a single line in the topology definition file is all that's needed:

Expand All @@ -17,15 +17,15 @@ topology:
nodes:
r1:
kind: srl
share:
- tcp/22 # tcp port 22 will be exposed
- tcp/57400 # tcp port 57400 will be exposed
- http/10200 # http service running over 10200 will be exposed
publish:
- tcp/22 # tcp port 22 will be published
- tcp/57400 # tcp port 57400 will be published
- http/10200 # http service running over 10200 will be published
```

<video width="100%" controls>
<!-- <video width="100%" controls>
<source src="https://gitlab.com/rdodin/pics/-/wikis/uploads/709405ded4ccf7387725b4fab1ab87f6/containerlab-mysocketio.mp4" type="video/mp4">
</video>
</video> -->

## Registration
Tunnels set up by mysocket.io are associated with a user who set them, thus users are required to register within the service. Luckily, the [registration](https://mysocket.readthedocs.io/en/latest/mysocketctl/mysocket.html#creating-an-account) is trivial, all you need to provide is an email and a public SSH key that will be used to set up tunnels.
Expand Down Expand Up @@ -57,20 +57,20 @@ The script will get the token and save it in the current directory under `mysock
The token is valid for 5 hours, once the token expires, the already established tunnels will continue to work, but to establish new tunnels a new token must be provided.

## Specify what to share
To indicate which ports to share the users need to add `share` section under node/kind or default level of the [topology definition file](topo-def-file.md). In the example below, we decide to share SSH and gNMI services of `r1` node:
To indicate which ports to publish the users need to add `publish` section under node/kind or default level of the [topology definition file](topo-def-file.md). In the example below, we decide to publish SSH and gNMI services of `r1` node:

```yaml
name: demo
topology:
nodes:
r1:
kind: srl
share:
publish:
- tcp/22 # tcp port 22 will be exposed
- tcp/57400 # tcp port 57400 will be exposed
```

The `share` section holds a list of `<type>/<port-number>` strings, where `type` must be one of the supported mysocket.io socket type[^2] - http/https/tls/tcp. Every type/port combination will be exposed via its own private tunnel.
The `publish` section holds a list of `<type>/<port-number>` strings, where `type` must be one of the supported mysocket.io socket type[^2] - http/https/tls/tcp. Every type/port combination will be exposed via its own private tunnel.

!!!note
For a single account the following maximum number of tunnels is set:
Expand All @@ -79,15 +79,15 @@ The `share` section holds a list of `<type>/<port-number>` strings, where `type`
If >5 tcp tunnels is required users should launch a VM in a lab, expose it's SSH service and use this VM as a jumpbox for other TCP services.

## Add mysocketio node
Containerlab integrates with mysocket.io service by leveraging it's client application packaged in a container format. In order for the sockets indicated in the `share` block to be exposed, a user needs to add a node of `mysocketio` kind to the topology. Augmenting the topology we used above, the full topology file will look like:
Containerlab integrates with mysocket.io service by leveraging it's client application packaged in a container format. In order for the sockets indicated in the `publish` block to be exposed, a user needs to add a node of `mysocketio` kind to the topology. Augmenting the topology we used above, the full topology file will look like:

```yaml
name: demo
topology:
nodes:
r1:
kind: srl
share:
publish:
- tcp/22 # tcp port 22 will be exposed
- tcp/57400 # tcp port 57400 will be exposed

Expand All @@ -100,16 +100,16 @@ topology:
- mysocketio_token:/root/.mysocketio_token # bind mount API token
```

The `mysocketio` node is a simple linux container with mysocketctl client installed. Containerlab uses this node to create the sockets and start tunnels as defined in the `share` block.
The `mysocketio` node is a simple linux container with mysocketctl client installed. Containerlab uses this node to create the sockets and start tunnels as defined in the `publish` block.

Pay specific attention to `binds` defined for mysocketio node. With this section we provide the two crucial artifacts:
* path to the private key, that matches the public key used during the registration
* path to the API token that we acquired before launching the lab

And that is all that is needed to expose the sockets in an automated way.

## Explore shared sockets
When a user launches a lab with shared ports it will be presented with a sockets table after the lab deployment process finishes:
## Explore published ports
When a user launches a lab with published ports it will be presented with a summary table after the lab deployment process finishes:

```
+---+-----------------------+--------------+---------------------------------+------------+-------+---------+----------------+----------------------+
Expand All @@ -118,17 +118,17 @@ When a user launches a lab with shared ports it will be presented with a sockets
| 1 | clab-sock-r1 | 9cefd6cdb239 | srlinux:20.6.3-145 | srl | | running | 172.20.20.2/24 | 2001:172:20:20::2/80 |
| 2 | clab-sock-mysocketctl | 8f5385beb97e | ghcr.io/hellt/mysocketctl:0.1.0 | mysocketio | | running | 172.20.20.3/24 | 2001:172:20:20::3/80 |
+---+-----------------------+--------------+---------------------------------+------------+-------+---------+----------------+----------------------+
Shared sockets:
Published ports:
┌──────────────────────────────────────┬──────────────────────────────────────┬─────────┬──────┬────────────┬────────────────────────┐
│ SOCKET ID │ DNS NAME │ PORT(S) │ TYPE │ CLOUD AUTH │ NAME │
├──────────────────────────────────────┼──────────────────────────────────────┼─────────┼──────┼────────────┼────────────────────────┤
│ 2b2808ae-b05d-4103-9b95-ab473a82658c │ nameless-bird-8969.edge.mysocket.io │ 16086 │ tcp │ false │ clab-tcp-22-r1 │
│ 8455571c-deea-4b09-bc1d-7a56f41e8c52 │ restless-night-8051.edge.mysocket.io │ 11107 │ tcp │ false │ clab-tcp-57400-r1 │
└──────────────────────────────────────┴──────────────────────────────────────┴─────────┴──────┴────────────┴────────────────────────┘
```
The **Shared sockets** table lists all the sockets and their corresponding DNS names. Looking at the NAME column users can quickly discover which tunnel corresponds to which node and its exposed port. The socket name follows the `clab-<type>-<port>-<node-name>` pattern.
The **Published ports** table lists the ports and their corresponding DNS names. Looking at the NAME column users can quickly discover which tunnel corresponds to which node and its published port. The socket name follows the `clab-<type>-<port>-<node-name>` pattern.

To use the shared port, users need to combine the DNS name and the Port to derive the full address. For the exposed SSH port, for example, the ssh client can use the following command to access remote SSH service:
To access the published port, users need to combine the DNS name and the Port to derive the full address. For the exposed SSH port, for example, the ssh client can use the following command to access remote SSH service:

```
ssh user@nameless-bird-8969.edge.mysocket.io -p 16086
Expand All @@ -141,7 +141,7 @@ To check the health status of the established tunnels execute the following comm
docker exec -it <mysocketio-node-name> /bin/sh -c "cat socket*"
```

This command will display all the logs for the shared sockets. If something is not right, you will see the erros in the log.
This command will display all the logs for the published ports. If something is not right, you will see the erros in the log.

[^1]: https://mysocket.readthedocs.io/en/latest/about/about.html#build-on-a-global-anycast-network
[^2]: https://mysocket.readthedocs.io/en/latest/about/about.html#features
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ nav:
- Network wiring concepts: manual/network.md
- Packet capture & Wireshark: manual/wireshark.md
- VM based routers integration: manual/vrnetlab.md
- Share lab access: manual/shared-sockets.md
- Publish ports: manual/published-ports.md
- Command reference:
- deploy: cmd/deploy.md
- destroy: cmd/destroy.md
Expand Down

0 comments on commit 6b9aefd

Please sign in to comment.