Search Postgresql Archives

Re: How to debug: password authentication failed for user

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thank you for the comments, I must think some time how to handle this.

My intention has been to generate 2 random strings in an Azure pipeline, save them as secrets in an Azure Key Vault (so that our C# ASP.Net app can fetch them when starting up in Kubernetes) and also pass them to the pipeline tasks, which would pass them as the build arg to the "docker build" command:

# Generate random passwords as save them as KV secrets
- task: AzurePowerShell@5
  displayName: 'Write PostgreSQL passwords to KV'
  inputs:
    azureSubscription: '${{ parameters.ArmConnection }}'
    ScriptType: 'InlineScript'
    azurePowerShellVersion: 'LatestVersion'
    Inline: |
      # Generate a random password for PUSH_PULL_PASS and store it in the KV
      $pushPullPass = ( -join ((0x30..0x39) + (0x41..0x5A) + (0x61..0x7A) | Get-Random -Count 20 | % {[char]$_}) )
      $pushPullSecret = ConvertTo-SecureString -String $pushPullPass -AsPlainText -Force
      Set-AzKeyVaultSecret -VaultName '${{ parameters.ResourceKeyVault }}' -Name PushPullPass -SecretValue $pushPullSecret
      # Generate a random password for TIMESHIFT_PASS and store it in the KV
      $timeshiftPass = ( -join ((0x30..0x39) + (0x41..0x5A) + (0x61..0x7A) | Get-Random -Count 20 | % {[char]$_}) )
      $timeshiftSecret = ConvertTo-SecureString -String $timeshiftPass -AsPlainText -Force
      Set-AzKeyVaultSecret -VaultName '${{ parameters.ResourceKeyVault }}' -Name TimeshiftPass -SecretValue $timeshiftSecret
      # Set the pipeline vars for the 2 docker builds below
      Write-Host "##vso[task.setvariable variable=PushPullPass]$pushPullPass"
      Write-Host "##vso[task.setvariable variable=TimeshiftPass]$timeshiftPass"

# build Push Pull DB docker file
- task: Docker@2
  displayName: Build Push Pull DB docker image
  inputs:
    command: build
    repository: '$(PushPullReponame)'
    dockerfile:  '$(Build.SourcesDirectory)/suuCcg/src/Services/SUU.PushPullDatabase/Dockerfile'
    arguments: "--no-cache --build-arg PGPASSWORD=$(PushPullPass)"
    tags: $(ImageTag)
    buildContext: '$(Build.SourcesDirectory)/suuCcg/src/'

# build Timeshift DB docker file
- task: Docker@2
  displayName: Build Timeshift DB docker image
  inputs:
    command: build
    repository: '$(TimeshiftReponame)'
    dockerfile:  '$(Build.SourcesDirectory)/suuCcg/src/Services/SUU.TimeshiftDatabase/Dockerfile'
    arguments: "--no-cache --build-arg PGPASSWORD=$(TimeshiftPass)"
    tags: $(ImageTag)
    buildContext: '$(Build.SourcesDirectory)/suuCcg/src/'

And then I am not done yet :-) I need to pass that random string from the Dockerfile to the 01-create-database.sql and I have tried it as env var:

# To build locally: docker build -f Services/SUU.TimeshiftDatabase/Dockerfile --build-arg PGPASSWORD=timeshift_pass .

# To run locally in Git Bash: winpty docker run --rm -it -p 5432:5432 sha256:...

FROM postgres:17-alpine3.21
RUN apk update && apk upgrade && apk add --no-cache pg_top

ARG PGPASSWORD

# Tell docker-entrypoint.sh to create superuser "postgres"
# with password passed as build arg and database "postgres"
ENV POSTGRES_PASSWORD=$PGPASSWORD

# Tell docker-entrypoint.sh to change these params in postgresql.conf
ENV POSTGRES_INITDB_ARGS="--set max_connections=200 \
                          --set shared_buffers=16GB \
                          --set work_mem=8MB \
                          --set maintenance_work_mem=128MB \
                          --set effective_cache_size=8GB \
                          --set from_collapse_limit=24 \
                          --set join_collapse_limit=24 \
                          --set log_min_messages=notice \
                          --set log_connections=on \
                          --set log_statement=all \
                          --set listen_addresses='*'"

ENV PGUSER=postgres
ENV PGPASSWORD=$PGPASSWORD
ENV PGDATABASE=timeshift_database

# The files below are executed by the DB superuser "postgres"
# in alphabetical order after the database has been initialized
WORKDIR /docker-entrypoint-initdb.d
COPY ./Services/SUU.TimeshiftDatabase/01-create-database.sql .

COPY ./Services/SUU.VehicleService/TimeshifCalculator/timeshift-create-tables.sql ./02-create-tables.sql
COPY ./Services/SUU.VehicleService/TimeshifCalculator/timeshift-create-functions.sql ./03-create-functions.sql
COPY ./Services/SUU.VehicleService/TimeshifCalculator/timeshift-smoke-tests.sql ./04-smoke-tests.sql

# Prepend \c timeshift_database to each SQL file using sed
RUN sed -i.bak '1i\\\\c timeshift_database' ./02-create-tables.sql
RUN sed -i.bak '1i\\\\c timeshift_database' ./03-create-functions.sql
RUN sed -i.bak '1i\\\\c timeshift_database' ./04-smoke-tests.sql

# Drop root privileges
USER postgres

But I see that the whole chain is tricky to implement and I'd like to switch from a postgres:17-alpine3.21 based Docker image to the "Azure PostgreSQL flexible server" product anyway, to have less maintenance.

Best regards
Alex




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux