Skip to content

Commit

Permalink
[TCQA] Extend change of permissions to Windows 2019 Server Core-based…
Browse files Browse the repository at this point in the history
… agent (#166)

* Use ContainerAdministrator account during the first build phase.

* Update permission set.
  • Loading branch information
AndreyKoltsov1997 authored Jul 17, 2024
1 parent 9ba5175 commit 8431dd1
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 20 deletions.
8 changes: 7 additions & 1 deletion configs/windows/Agent/nanoserver/NanoServer1809.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,15 @@ ENV CONFIG_FILE="C:\BuildAgent\conf\buildAgent.properties" \
# Skip extraction of XML docs - generally not useful within an image/container - helps perfomance
NUGET_XMLDOC_MODE=skip

# In order to set system PATH, ContainerAdministrator must be used
# Use ContainerAdministrator to update permissions and PATH
USER ContainerAdministrator
RUN setx /M PATH "%PATH%;%JAVA_HOME%\bin;C:\Program Files\Git\cmd;C:\Program Files\dotnet"
# Grant Permissions for ContainerUser (Default Account), OI - Object Inherit, CI - Container Inherit, ...
# ... F - full control, D - delete (critical for upgrade), /T - apply to subfolders & files
RUN cmd /c icacls.exe C:\\BuildAgent /grant:r DefaultAccount:(OI)(CI)F /grant:r DefaultAccount:(OI)(CI)D /T
RUN cmd /c icacls.exe C:\\BuildAgent /grant:r Users:(OI)(CI)F /grant:r Users:(OI)(CI)D /T
# Applied permission check for logging purposes
RUN cmd /c icacls.exe C:\\BuildAgent\\*
USER ContainerUser

# Trigger first run experience by running arbitrary cmd to populate local package cache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ ENV CONFIG_FILE="C:\BuildAgent\conf\buildAgent.properties" \
# Skip extraction of XML docs - generally not useful within an image/container - helps perfomance
NUGET_XMLDOC_MODE=skip


USER ContainerAdministrator
RUN setx /M PATH ('{0};{1}\bin;C:\Program Files\Git\cmd;C:\Program Files\Mercurial' -f $env:PATH, $env:JAVA_HOME)
USER ContainerUser
# Grant Permissions for ContainerUser (Default Account), OI - Object Inherit, CI - Container Inherit, ...
# ... F - full control, D - delete, /T - apply to subfolders & files
RUN cmd /c icacls.exe "C:\\BuildAgent" /grant:r 'DefaultAccount:(OI)(CI)F' /grant:r 'DefaultAccount:(OI)(CI)D' /T
RUN cmd /c icacls.exe "C:\\BuildAgent" /grant:r 'Users:(OI)(CI)F' /grant:r 'Users:(OI)(CI)D' /T
# Applied permission check for logging purposes
RUN cmd /c icacls.exe C:\\BuildAgent\\*
USER ContainerUser
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ FROM ${powershellImage} AS base
# ... PowerShell container.
USER ContainerAdministrator

COPY scripts/*.cs /scripts/
SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

# Prepare build agent distribution
RUN mkdir C:\\BuildAgent
COPY TeamCity/buildAgent C:/BuildAgent

COPY scripts/*.cs /scripts/
SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

COPY run-agent.ps1 /BuildAgent/run-agent.ps1

# JDK
Expand Down Expand Up @@ -86,7 +86,6 @@ ENV JAVA_HOME="C:\Program Files\Java\OpenJDK" \

COPY --chown=ContainerUser --from=base /BuildAgent /BuildAgent

# Use ContainerAdministrator to update permissions
USER ContainerAdministrator
# Grant Permissions for ContainerUser (Default Account), OI - Object Inherit, CI - Container Inherit, ...
# ... F - full control, D - delete, /T - apply to subfolders & files
Expand All @@ -101,4 +100,4 @@ VOLUME C:/BuildAgent/work
VOLUME C:/BuildAgent/temp
VOLUME C:/BuildAgent/logs

CMD ["pwsh", "./BuildAgent/run-agent.ps1"]
CMD ["pwsh", "./BuildAgent/run-agent.ps1"]
8 changes: 7 additions & 1 deletion context/generated/windows/Agent/nanoserver/1809/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,15 @@ ENV CONFIG_FILE="C:\BuildAgent\conf\buildAgent.properties" \
# Skip extraction of XML docs - generally not useful within an image/container - helps perfomance
NUGET_XMLDOC_MODE=skip

# In order to set system PATH, ContainerAdministrator must be used
# Use ContainerAdministrator to update permissions and PATH
USER ContainerAdministrator
RUN setx /M PATH "%PATH%;%JAVA_HOME%\bin;C:\Program Files\Git\cmd;C:\Program Files\dotnet"
# Grant Permissions for ContainerUser (Default Account), OI - Object Inherit, CI - Container Inherit, ...
# ... F - full control, D - delete (critical for upgrade), /T - apply to subfolders & files
RUN cmd /c icacls.exe C:\\BuildAgent /grant:r DefaultAccount:(OI)(CI)F /grant:r DefaultAccount:(OI)(CI)D /T
RUN cmd /c icacls.exe C:\\BuildAgent /grant:r Users:(OI)(CI)F /grant:r Users:(OI)(CI)D /T
# Applied permission check for logging purposes
RUN cmd /c icacls.exe C:\\BuildAgent\\*
USER ContainerUser

# Trigger first run experience by running arbitrary cmd to populate local package cache
Expand Down
8 changes: 7 additions & 1 deletion context/generated/windows/Agent/nanoserver/1903/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,15 @@ ENV CONFIG_FILE="C:\BuildAgent\conf\buildAgent.properties" \
# Skip extraction of XML docs - generally not useful within an image/container - helps perfomance
NUGET_XMLDOC_MODE=skip

# In order to set system PATH, ContainerAdministrator must be used
# Use ContainerAdministrator to update permissions and PATH
USER ContainerAdministrator
RUN setx /M PATH "%PATH%;%JAVA_HOME%\bin;C:\Program Files\Git\cmd;C:\Program Files\dotnet"
# Grant Permissions for ContainerUser (Default Account), OI - Object Inherit, CI - Container Inherit, ...
# ... F - full control, D - delete (critical for upgrade), /T - apply to subfolders & files
RUN cmd /c icacls.exe C:\\BuildAgent /grant:r DefaultAccount:(OI)(CI)F /grant:r DefaultAccount:(OI)(CI)D /T
RUN cmd /c icacls.exe C:\\BuildAgent /grant:r Users:(OI)(CI)F /grant:r Users:(OI)(CI)D /T
# Applied permission check for logging purposes
RUN cmd /c icacls.exe C:\\BuildAgent\\*
USER ContainerUser

# Trigger first run experience by running arbitrary cmd to populate local package cache
Expand Down
8 changes: 7 additions & 1 deletion context/generated/windows/Agent/nanoserver/1909/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,15 @@ ENV CONFIG_FILE="C:\BuildAgent\conf\buildAgent.properties" \
# Skip extraction of XML docs - generally not useful within an image/container - helps perfomance
NUGET_XMLDOC_MODE=skip

# In order to set system PATH, ContainerAdministrator must be used
# Use ContainerAdministrator to update permissions and PATH
USER ContainerAdministrator
RUN setx /M PATH "%PATH%;%JAVA_HOME%\bin;C:\Program Files\Git\cmd;C:\Program Files\dotnet"
# Grant Permissions for ContainerUser (Default Account), OI - Object Inherit, CI - Container Inherit, ...
# ... F - full control, D - delete (critical for upgrade), /T - apply to subfolders & files
RUN cmd /c icacls.exe C:\\BuildAgent /grant:r DefaultAccount:(OI)(CI)F /grant:r DefaultAccount:(OI)(CI)D /T
RUN cmd /c icacls.exe C:\\BuildAgent /grant:r Users:(OI)(CI)F /grant:r Users:(OI)(CI)D /T
# Applied permission check for logging purposes
RUN cmd /c icacls.exe C:\\BuildAgent\\*
USER ContainerUser

# Trigger first run experience by running arbitrary cmd to populate local package cache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ ENV CONFIG_FILE="C:\BuildAgent\conf\buildAgent.properties" \
# Skip extraction of XML docs - generally not useful within an image/container - helps perfomance
NUGET_XMLDOC_MODE=skip


USER ContainerAdministrator
RUN setx /M PATH ('{0};{1}\bin;C:\Program Files\Git\cmd;C:\Program Files\Mercurial' -f $env:PATH, $env:JAVA_HOME)
# Grant Permissions for ContainerUser (Default Account), OI - Object Inherit, CI - Container Inherit, ...
# ... F - full control, D - delete, /T - apply to subfolders & files
RUN cmd /c icacls.exe "C:\\BuildAgent" /grant:r 'DefaultAccount:(OI)(CI)F' /grant:r 'DefaultAccount:(OI)(CI)D' /T
RUN cmd /c icacls.exe "C:\\BuildAgent" /grant:r 'Users:(OI)(CI)F' /grant:r 'Users:(OI)(CI)D' /T
# Applied permission check for logging purposes
RUN cmd /c icacls.exe C:\\BuildAgent\\*
USER ContainerUser
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ ENV CONFIG_FILE="C:\BuildAgent\conf\buildAgent.properties" \
# Skip extraction of XML docs - generally not useful within an image/container - helps perfomance
NUGET_XMLDOC_MODE=skip


USER ContainerAdministrator
RUN setx /M PATH ('{0};{1}\bin;C:\Program Files\Git\cmd;C:\Program Files\Mercurial' -f $env:PATH, $env:JAVA_HOME)
# Grant Permissions for ContainerUser (Default Account), OI - Object Inherit, CI - Container Inherit, ...
# ... F - full control, D - delete, /T - apply to subfolders & files
RUN cmd /c icacls.exe "C:\\BuildAgent" /grant:r 'DefaultAccount:(OI)(CI)F' /grant:r 'DefaultAccount:(OI)(CI)D' /T
RUN cmd /c icacls.exe "C:\\BuildAgent" /grant:r 'Users:(OI)(CI)F' /grant:r 'Users:(OI)(CI)D' /T
# Applied permission check for logging purposes
RUN cmd /c icacls.exe C:\\BuildAgent\\*
USER ContainerUser
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ ENV CONFIG_FILE="C:\BuildAgent\conf\buildAgent.properties" \
# Skip extraction of XML docs - generally not useful within an image/container - helps perfomance
NUGET_XMLDOC_MODE=skip


USER ContainerAdministrator
RUN setx /M PATH ('{0};{1}\bin;C:\Program Files\Git\cmd;C:\Program Files\Mercurial' -f $env:PATH, $env:JAVA_HOME)
# Grant Permissions for ContainerUser (Default Account), OI - Object Inherit, CI - Container Inherit, ...
# ... F - full control, D - delete, /T - apply to subfolders & files
RUN cmd /c icacls.exe "C:\\BuildAgent" /grant:r 'DefaultAccount:(OI)(CI)F' /grant:r 'DefaultAccount:(OI)(CI)D' /T
RUN cmd /c icacls.exe "C:\\BuildAgent" /grant:r 'Users:(OI)(CI)F' /grant:r 'Users:(OI)(CI)D' /T
# Applied permission check for logging purposes
RUN cmd /c icacls.exe C:\\BuildAgent\\*
USER ContainerUser
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ ENV CONFIG_FILE="C:\BuildAgent\conf\buildAgent.properties" \
# Skip extraction of XML docs - generally not useful within an image/container - helps perfomance
NUGET_XMLDOC_MODE=skip


USER ContainerAdministrator
RUN setx /M PATH ('{0};{1}\bin;C:\Program Files\Git\cmd;C:\Program Files\Mercurial' -f $env:PATH, $env:JAVA_HOME)
# Grant Permissions for ContainerUser (Default Account), OI - Object Inherit, CI - Container Inherit, ...
# ... F - full control, D - delete, /T - apply to subfolders & files
RUN cmd /c icacls.exe "C:\\BuildAgent" /grant:r 'DefaultAccount:(OI)(CI)F' /grant:r 'DefaultAccount:(OI)(CI)D' /T
RUN cmd /c icacls.exe "C:\\BuildAgent" /grant:r 'Users:(OI)(CI)F' /grant:r 'Users:(OI)(CI)D' /T
# Applied permission check for logging purposes
RUN cmd /c icacls.exe C:\\BuildAgent\\*
USER ContainerUser
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ FROM ${powershellImage} AS base
# ... PowerShell container.
USER ContainerAdministrator

COPY scripts/*.cs /scripts/
SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

# Prepare build agent distribution
RUN mkdir C:\\BuildAgent
COPY TeamCity/buildAgent C:/BuildAgent

COPY scripts/*.cs /scripts/
SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

COPY run-agent.ps1 /BuildAgent/run-agent.ps1

# JDK
Expand Down Expand Up @@ -79,7 +79,6 @@ ENV JAVA_HOME="C:\Program Files\Java\OpenJDK" \

COPY --chown=ContainerUser --from=base /BuildAgent /BuildAgent

# Use ContainerAdministrator to update permissions
USER ContainerAdministrator
# Grant Permissions for ContainerUser (Default Account), OI - Object Inherit, CI - Container Inherit, ...
# ... F - full control, D - delete, /T - apply to subfolders & files
Expand Down
19 changes: 17 additions & 2 deletions context/generated/windows/MinimalAgent/nanoserver/1903/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ ARG powershellImage='mcr.microsoft.com/powershell:nanoserver-1903'

FROM ${powershellImage} AS base

COPY scripts/*.cs /scripts/
SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
# On some agents, Windows 2019 requires administrator permissions to modify "C:/" folder within ...
# ... PowerShell container.
USER ContainerAdministrator

# Prepare build agent distribution
RUN mkdir C:\\BuildAgent
COPY TeamCity/buildAgent C:/BuildAgent

COPY scripts/*.cs /scripts/
SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

COPY run-agent.ps1 /BuildAgent/run-agent.ps1

# JDK
Expand Down Expand Up @@ -73,6 +79,15 @@ ENV JAVA_HOME="C:\Program Files\Java\OpenJDK" \

COPY --chown=ContainerUser --from=base /BuildAgent /BuildAgent

USER ContainerAdministrator
# Grant Permissions for ContainerUser (Default Account), OI - Object Inherit, CI - Container Inherit, ...
# ... F - full control, D - delete, /T - apply to subfolders & files
RUN cmd /c icacls.exe C:\\BuildAgent /grant:r DefaultAccount:(OI)(CI)F /grant:r DefaultAccount:(OI)(CI)D /T
RUN cmd /c icacls.exe C:\\BuildAgent /grant:r Users:(OI)(CI)F /grant:r Users:(OI)(CI)D /T
# Applied permission check for logging purposes
RUN cmd /c icacls.exe C:\\BuildAgent\\*
USER ContainerUser

VOLUME C:/BuildAgent/conf
VOLUME C:/BuildAgent/work
VOLUME C:/BuildAgent/temp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ FROM ${powershellImage} AS base
# ... PowerShell container.
USER ContainerAdministrator

COPY scripts/*.cs /scripts/
SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

# Prepare build agent distribution
RUN mkdir C:\\BuildAgent
COPY TeamCity/buildAgent C:/BuildAgent

COPY scripts/*.cs /scripts/
SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

COPY run-agent.ps1 /BuildAgent/run-agent.ps1

# JDK
Expand Down Expand Up @@ -79,7 +79,6 @@ ENV JAVA_HOME="C:\Program Files\Java\OpenJDK" \

COPY --chown=ContainerUser --from=base /BuildAgent /BuildAgent

# Use ContainerAdministrator to update permissions
USER ContainerAdministrator
# Grant Permissions for ContainerUser (Default Account), OI - Object Inherit, CI - Container Inherit, ...
# ... F - full control, D - delete, /T - apply to subfolders & files
Expand Down

0 comments on commit 8431dd1

Please sign in to comment.