generated from oracle-devrel/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 83
Ios py bastion #1509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Ios py bastion #1509
Changes from 10 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b7c3786
initial commit of the asset
bios62 8d0c0bc
updated securty-design README
bios62 918789e
111824V2
bios62 350f97b
111824V3
bios62 23e61e9
111824V4
bios62 37f41ef
111824V5 added License to README
bios62 d26aae2
adjusted code after review
bios62 b6590b0
After Flake8
bios62 513e8cc
Merge branch 'main' into ios-py-bastion
bios62 bdd628d
Spell check
bios62 0c8caf9
Update LICENSE
AlexanderHodicke 0599c28
Update constants.py
AlexanderHodicke e1a0cce
Update bastionsession.py
AlexanderHodicke 21f6990
Merge branch 'main' into ios-py-bastion
AlexanderHodicke a722050
Update bastionsession.py
bios62 e6521a6
Update constants.py
bios62 de30279
Merge branch 'main' into ios-py-bastion
oheimburger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,35 +1,4 @@ | ||
| # General | ||
| .DS_Store | ||
| .AppleDouble | ||
| .LSOverride | ||
| .vscode | ||
| .bak | ||
|
|
||
| # Icon must end with two \r | ||
| Icon | ||
|
|
||
|
|
||
| # Thumbnails | ||
| ._* | ||
|
|
||
| # Files that might appear in the root of a volume | ||
| .DocumentRevisions-V100 | ||
| .fseventsd | ||
| .Spotlight-V100 | ||
| .TemporaryItems | ||
| .Trashes | ||
| .VolumeIcon.icns | ||
| .com.apple.timemachine.donotpresent | ||
|
|
||
| # Directories potentially created on remote AFP share | ||
| .AppleDB | ||
| .AppleDesktop | ||
| Network Trash Folder | ||
| Temporary Items | ||
| .apdisk | ||
|
|
||
| # ignore common security keys | ||
| .key | ||
| .crt | ||
| .csr | ||
| .pem | ||
| .gitignore | ||
| shared-assets/bastion-py-script/.oci/ | ||
| shared-assets/bastion-py-script/temp/ | ||
| temp/ |
This file contains hidden or 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
35 changes: 35 additions & 0 deletions
35
security/security-design/shared-assets/bastion-py-script/LICENSE
This file contains hidden or 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,35 @@ | ||
| Copyright (c) 2024 Oracle and/or its affiliates. | ||
AlexanderHodicke marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| The Universal Permissive License (UPL), Version 1.0 | ||
|
|
||
| Subject to the condition set forth below, permission is hereby granted to any | ||
| person obtaining a copy of this software, associated documentation and/or data | ||
| (collectively the "Software"), free of charge and under any and all copyright | ||
| rights in the Software, and any and all patent rights owned or freely | ||
| licensable by each licensor hereunder covering either (i) the unmodified | ||
| Software as contributed to or provided by such licensor, or (ii) the Larger | ||
| Works (as defined below), to deal in both | ||
|
|
||
| (a) the Software, and | ||
| (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if | ||
| one is included with the Software (each a "Larger Work" to which the Software | ||
| is contributed by such licensors), | ||
|
|
||
| without restriction, including without limitation the rights to copy, create | ||
| derivative works of, display, perform, and distribute the Software and make, | ||
| use, sell, offer for sale, import, export, have made, and have sold the | ||
| Software and the Larger Work(s), and to sublicense the foregoing rights on | ||
| either these or other terms. | ||
|
|
||
| This license is subject to the following condition: | ||
| The above copyright notice and either this complete permission notice or at | ||
| a minimum a reference to the UPL must be included in all copies or | ||
| substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. | ||
141 changes: 141 additions & 0 deletions
141
security/security-design/shared-assets/bastion-py-script/README.md
This file contains hidden or 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,141 @@ | ||
|
|
||
| # Oracle Cloud Infrastructure (OCI) Bastion Service | ||
|
|
||
| This reusable asset consist of a Python script that creates a bastion session with the Oracle OCI Bastion Service. The main purposes of this asset are: | ||
|
|
||
| - Demonstrate the usage of OCI Python SDK | ||
| - Create a simple OS independent command-line interface for creating bastion sessions | ||
| - Create a simple way to make reusable configuration | ||
| - Create a `ssh` command that works with Linux, Mac OS and Windows by providing the flexibility to configure either `ssh` command or `putty` commands. | ||
|
|
||
| The script creates bastion session over SSH, and creates an example command to set up the tunnel for the target application. Other protocols like RDP can then be tunneled over the SSH session through the OCI Bastion Service. | ||
|
|
||
| Some documentation for inspiraton: | ||
|
|
||
| [https://www.ateam-oracle.com/post/openssh-proxyjump-with-oci-bastion-service](https://www.ateam-oracle.com/post/openssh-proxyjump-with-oci-bastion-service) | ||
| [https://fluffyclouds.blog/2022/06/02/create-oci-bastion-sessions-with-python-sdk/](https://fluffyclouds.blog/2022/06/02/create-oci-bastion-sessions-with-python-sdk/) | ||
|
|
||
| ## Why use the OCI Bastion Service | ||
|
|
||
| Oracle Cloud Infrastructure (OCI) Bastion Service, is a fully managed service providing secure and ephemeral Secure Shell (ssh) access to the private resources in OCI. OCI Bastion Service, like the bastion fortress of medieval times, improves security posture by providing an additional layer of defense against external threats. | ||
|
|
||
| Accessing virtual services directly from the internet is a clear no-go. Best practices is to never expose compute resources directly, neither for SSH or RDP traffic. RDP is known to be one of the most common Initial Access Vectors for ransomware types of attacks. | ||
|
|
||
| Common practice is to place a compute node with a minimum OS in a DMZ as jump host, and always use this as the entrypoint. | ||
| The main weakness with this model is: | ||
| - A extra computer-node that needs to be managed, monitored and patched | ||
| - Extra set of required resources with risk of misconfiguration | ||
| - The jump server will require an additional layer of user governance. | ||
|
|
||
| The OCI Bastion Service removes the public and private virtual cloud networking (VCN) hassle for access to a jump host. No public IP is needed, resulting in no surface attack area or zero-day vulnerabilities with a dedicated jump host. Customers also eliminate shared credentials, broad access limits, and other bad habits of using jump hosts. OCI Bastion Service integrates with OCI Identity and Access Management (IAM) and allows the organization to control who can access a bastion or a session and what they can do with those resources. | ||
|
|
||
| The OCI Bastion Service exists in two flavors: | ||
| - Managed Session | ||
| With managed sessions an agent is running on the compute node, and the bastion session connects to the agent and tunnels SSH through the agent. The managed session makes it possible to connect to a compute node from other networks without configure routing between the network where the compute node resides, and the network the bastion connection is initiated from. | ||
| - Port Forwarding | ||
| In this mode the OCI Bastion Service does not tunnel though the agent, but the OCI Bastion Service must have access to the subnet where the compute node resides, and the subnet security list | ||
| For additional description of the OCI Bastion Service please review: | ||
|
|
||
| ## Requirements | ||
|
|
||
| The following components needs to be installed in your environment: | ||
| - Python 3.8 or above (latest patch version) | ||
| - Latest version of the OCI CLI | ||
| - Requirements, as defined in requirements.txt | ||
|
|
||
| If you need to run older Python versions (below 3.8), note the changes for asyncio in the exec_command procedure. | ||
|
|
||
| [OCI CLI Install guide](https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/cliinstall.htm) | ||
|
|
||
| The file requirements.txt lists the Python modules required. | ||
| Install the required modules with | ||
|
|
||
| ```pip install -r requirements.txt``` | ||
|
|
||
|
|
||
| ## Script Usage | ||
|
|
||
| In addition, the script require a JSON configuration file. | ||
|
|
||
| The basic structure of the config file looks like: | ||
| ``` | ||
| { "sessions":[ | ||
| { <session one points to ociconfigurations>}, | ||
| { <session two points to ociconfigurations>}], | ||
| "ociconfigurations": [ | ||
| { <ociconfiguration one>}, | ||
| { <ociconfiguration one>}] | ||
| } | ||
| ``` | ||
| For example, review [config_example.json](files/config_example.json) | ||
|
|
||
| The following elements exists in the configuration file. | ||
|
|
||
| - "sessions": JSON array with one JSON config entry pr. Session | ||
| - "ociconfigurations": JSON Array with one JSON element pr. OCI SDK configuration profile. | ||
|
|
||
| Each “session” element has the following elements: | ||
| - "sessionType":"PORT_FORWARDING" or MANAGED | ||
| - "OCIConfig"-: name of profile, it looked up in the ociconfigurations array | ||
| - "bastionOCID": OCID to the configured OCI Bastion service | ||
| - "bastionPublicKeyFile":file with public key to the Bastion SSH session | ||
| - "bastionPrivateKeyFile":Private key of bastion session key pair, | ||
| - "targetPrivateKeyFile":Used for reference in the target `ssh` command, | ||
| - "targetPort": Portnumber for the target SSH tunnel though the bastions Service. Use standard port for RDP if target is RDP, | ||
| - "localPort":"2222", | ||
| - "sessionDisplayName": Display name of the session in the OCI Console | ||
| - "sshCommand": For linux, normally, for windows, normally putty teh command that will be generated into the tunnel command | ||
| - "sshCommandOptions": applied to the tunnel comamndline, like ssh timeout options | ||
| - "targetOCIDID":OCID of the target service, | ||
| - "targetPrivateIP":IP Address of the target | ||
| - "osUserName": Used for the generated `ssh` command , | ||
| - "ociRegion": Region where the target resource runs, | ||
| - "timetolive":Time the Bastion tunnel lives. Maximum value is 3600 sec., | ||
| - "maxWaitCount":If the script creates the tunnel after creation of the session, maximum number of retries | ||
| - "waitRefresh": time in sec, between each retry to establish the tunnel | ||
| - "ociconfigurations": Array of OCI configurations | ||
|
|
||
| Each array entry got the following JSON elements | ||
| - "configName": Name of entry. Referenced from a session element above | ||
| - "configFileName": Path to the OCI CLI configuration file | ||
| - "profileName": Name of profile in the OCI CLI configuration file | ||
|
|
||
|
|
||
| ```Script commandline options. | ||
| --configfile name of JSON configfile with named session and OCI CLI config info | ||
| --session named session, section in config file | ||
| --exec executes the `ssh` command and establishes the SSH connection | ||
| --loglevel logging level, info or debug. default info | ||
| --log logging output file or stdout, defaul stdout | ||
| ``` | ||
| Example command: | ||
|
|
||
| Example commandline: | ||
| ```python bastionsession.py --session port-example --configfile config_examlpe.json --loglevel debug``` | ||
|
|
||
| Sample output | ||
|
|
||
| ``` | ||
| Bastion session manager 1.0 26.02.25 | ||
|
|
||
| INFO:root:Open logfile | ||
| Open logfile: stderr | ||
| Successfully loaded session and OCI Config parameters | ||
| Waiting for session state to be active. Current State ..CREATING | ||
| Session has been created and is ACTIVE | ||
| Bastion session created | ||
| Port managed start cmd | ||
| Port forwarding start cmd | ||
| ssh -i <privateKey> -N -L <localPort>:10.10.1.229:22 -p 22 ocid1.bastionsession.oc1.eu-frankfurt-1.ama...ama@host.bastion.eu-frankfurt-1.oci.oraclecloud.com | ||
| ssh tunnel command: | ||
| putty -i c:\\usr\\ssh_keys\\mykey.ppk -N -ssh -L 2222:10.10.1.229:22 ocid1.bastionsession.oc1.eu-frankfurt-1.ama...ama@host.bastion.eu-frankfurt-1.oci.oraclecloud.com | ||
| Client Connect: | ||
| putty -i c:\\usr\\ssh_keys\\myprivatetkey.ppk -P 2222 ios@localhost | ||
| Successfully completed bastion session(s) | ||
| ``` | ||
|
|
||
| # License | ||
|
|
||
| Copyright (c) 2025 Oracle and/or its affiliates. | ||
|
|
||
| Licensed under the Universal Permissive License (UPL), Version 1.0. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.