Skip to content

Commit 48bb6d4

Browse files
committed
Initial commit of bastion-session-script.
1 parent fd0d713 commit 48bb6d4

File tree

4 files changed

+605
-0
lines changed

4 files changed

+605
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Copyright (c) 2021 Oracle and/or its affiliates.
2+
3+
The Universal Permissive License (UPL), Version 1.0
4+
5+
Subject to the condition set forth below, permission is hereby granted to any
6+
person obtaining a copy of this software, associated documentation and/or data
7+
(collectively the "Software"), free of charge and under any and all copyright
8+
rights in the Software, and any and all patent rights owned or freely
9+
licensable by each licensor hereunder covering either (i) the unmodified
10+
Software as contributed to or provided by such licensor, or (ii) the Larger
11+
Works (as defined below), to deal in both
12+
13+
(a) the Software, and
14+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
15+
one is included with the Software (each a "Larger Work" to which the Software
16+
is contributed by such licensors),
17+
18+
without restriction, including without limitation the rights to copy, create
19+
derivative works of, display, perform, and distribute the Software and make,
20+
use, sell, offer for sale, import, export, have made, and have sold the
21+
Software and the Larger Work(s), and to sublicense the foregoing rights on
22+
either these or other terms.
23+
24+
This license is subject to the following condition:
25+
The above copyright notice and either this complete permission notice or at
26+
a minimum a reference to the UPL must be included in all copies or
27+
substantial portions of the Software.
28+
29+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35+
SOFTWARE.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# bastion-session.sh
2+
3+
This shell script can be used to easily connect to the OCI Bastion service based on temporary SSH keys. Authorization is granted based on OCI CLI authentication and OCI Permissions. For OCI CLI authentication both the use of exchanged API keys and session security tokens is supported. This script works also directly on OCI Cloud Shell, however only for Managed SSH Sessions since port forwarding is not supported on OCI Cloud Shell.
4+
5+
**Usage: ./bastion-session.sh COMMAND [ARGS]...**
6+
7+
Example:
8+
9+
```text
10+
./bastion-session.sh ssh -b bst001 -i instance-001 -u opc [-p <oci profile>]
11+
./bastion-session.sh pf -b bst001 -d 10.0.0.1 -e 3389 [-p <oci profile>] [-l <local port>]
12+
```
13+
14+
**Commands:**
15+
16+
ssh : The session type "ssh" for Managed SSH session.
17+
18+
pf : The session type "pf" for Port Forwarding session.
19+
20+
**Arguments:**
21+
22+
| short | long | description |
23+
|----|-----------------------------|---|
24+
| -b | --bastion TEXT | The Name of the Bastion to be used. [-b or -c is required]|
25+
| -c | --bastion-ocid TEXT | The OCID of the Bastion to be used. [-b or -c is required]|
26+
| -i | --instance TEXT | The name of the target instance to be used.|
27+
| -j | --instance-ocid TEXT | The OCID of the target instance to be used.|
28+
| -u | --username TEXT | The target resource username to be used. [default: opc]|
29+
| -p | --profile TEXT | The oci profile in the config file to load. [default: DEFAULT]|
30+
| -s | --session TEXT | The Bastion session name. [default: Bastion-Session]|
31+
| -t | --ttl INTEGER | The Bastion session time-to-live in seconds, minimum 1800, maximum 10800. [default: 10800]|
32+
| -d | --destination-ip IP | The destination IP Address to be used for Bastion session. [default: the first private ip address of instance]|
33+
| -e | --destination-port INTEGER | The destination port to be used for Port Forwarding session. [default: 22]|
34+
| -l | --local-port INTEGER | The local port to be used for Port Forwarding session. [defaults to same value as destination port]|
35+
| -a | --key-alg TEXT | The algorithm for the SSH key (ssh-keygen) to be used. [default: rsa]|
36+
| -k | --key-size INTEGER | The key size for the SSH key (ssh-keygen) to be used. [default: 4096]|
37+
| -pr| --private-key TEXT | The private key file to be used when not generating a temporary key pair. [by default not used]|
38+
| -pu| --public-key TEXT | The public key file to be used when not generating a temporary key pair. [by default not used]|
39+
| -v | --verbose | Show verbose output for troubleshooting.|
40+
41+
Prerequisites:
42+
43+
- The OCI Command Line Interface (CLI) must be installed and configured.
44+
(See also [https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/cliinstall.htm])
45+
- The jq commandline JSON processer must be installed.
46+
(See also [https://stedolan.github.io/jq])

0 commit comments

Comments
 (0)