Skip to content

Commit

Permalink
Merge branch 'main' into fix/change-response-code-on-update-deleted-d…
Browse files Browse the repository at this point in the history
…ialog
  • Loading branch information
oskogstad authored Dec 2, 2024
2 parents 0c9c148 + 580a095 commit 66cf9e6
Show file tree
Hide file tree
Showing 3 changed files with 388 additions and 10 deletions.
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,22 +313,24 @@ Use the following steps:

#### Connecting to resources in Azure

There is a `ssh-jumper` virtual machine deployed with the infrastructure. This can be used to create a `ssh`-tunnel into the `vnet`. Use one of the following methods to gain access to resources within the `vnet`:
There is a `ssh-jumper` virtual machine deployed with the infrastructure. This can be used to create a `ssh`-tunnel into the `vnet`. There are two ways to establish connections:

Ensure you log into the azure CLI using the relevant user and subscription using `az login`.

- Connect to the VNet using the following command:
```
1. Using `az ssh` commands directly:
```bash
# Connect to the VNet using:
az ssh vm --resource-group dp-be-<env>-rg --vm-name dp-be-<env>-ssh-jumper
```
(You may be prompted to install the ssh extension for the azure cli)

- To create an SSH tunnel for accessing specific resources (e.g., PostgreSQL database), use:
```

# Or create an SSH tunnel for specific resources (e.g., PostgreSQL database):
az ssh vm -g dp-be-<env>-rg -n dp-be-<env>-ssh-jumper -- -L 5432:<database-host-name>:5432
```
This example forwards the PostgreSQL default port (5432) to your localhost. Adjust the ports and hostnames as needed for other resources.

You may be prompted to install the ssh extension.

2. Using the forwarding utility script:

See [scripts/forward-bash/README.md](scripts/forward-bash/README.md) for a more user-friendly way to establish database connections through SSH.

### Applications

All application Bicep definitions are located in the `.azure/applications` folder. To add a new application, follow the existing pattern found within this directory. This involves creating a new folder for your application under `.azure/applications` and adding the necessary Bicep files (`main.bicep` and environment-specific parameter files, e.g., `test.bicepparam`, `staging.bicepparam`).
Expand Down
91 changes: 91 additions & 0 deletions scripts/database-forwarder/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Database Connection Forwarding

This utility helps forward PostgreSQL and Redis connections through SSH for Dialogporten environments.

## Prerequisites

- Azure CLI installed and configured
- Appropriate Azure account access
- Bash shell environment

## Usage

### Interactive Mode

Run the script without arguments for interactive mode:
```bash
./forward.sh
```

### Command-line Arguments

You can also specify the environment and database type directly:
```bash
./forward.sh -e test -t postgres
./forward.sh -e prod -t redis
```

Available options:
- `-e`: Environment (test, yt01, staging, prod)
- `-t`: Database type (postgres, redis)
- `-h`: Show help message

## Connecting to Databases

### PostgreSQL

1. Start the forwarding tool:
```bash
./forward.sh -e test -t postgres
```
2. Once the tunnel is established, you can connect using:
- Host: localhost
- Port: 5432
- Database: dialogporten
- Username: shown in the connection string
- Password: retrieve from Azure Key Vault

Example using psql:
```bash
psql "host=localhost port=5432 dbname=dialogporten user=<username>"
```

Example using pgAdmin:
- Host: localhost
- Port: 5432
- Database: dialogporten
- Username: (from connection string)
- Password: (from Key Vault)

### Redis

1. Start the forwarding tool:
```bash
./forward.sh -e test -t redis
```
2. Once the tunnel is established, you can connect using:
- Host: localhost
- Port: 6379
- Password: shown in the connection string

Example using redis-cli:
```bash
redis-cli -h localhost -p 6379 -a "<password>"
```

Example connection string for applications:
```plaintext
redis://:<password>@localhost:6379
```

## Troubleshooting

- If you get authentication errors, ensure you're logged into the correct Azure account:
- For test/yt01 environments, use the test subscription
- For staging/prod environments, use the production subscription
- If the tunnel fails to establish, try running `az login` again
- Make sure you have the necessary permissions in the Azure subscription
- If the script fails to execute, ensure it has execute permissions:
```bash
chmod +x forward.sh
```
Loading

0 comments on commit 66cf9e6

Please sign in to comment.