Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit ecf33c2

Browse files
committed
Fix gnome keyring token encryption
1 parent cb7a9a7 commit ecf33c2

File tree

8 files changed

+69
-21
lines changed

8 files changed

+69
-21
lines changed

.dockerignore

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/.git/
2-
/.github/
3-
/.vs/
4-
/.vscode/
5-
/src/[Bb]in/
6-
/src/[Oo]bj/
1+
**/.git/
2+
**/.github/
3+
**/.vs/
4+
**/.vscode/
5+
**/[Bb]in/
6+
**/[Oo]bj/

Dockerfile

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
1+
# To get around the bug in https://github.com/moby/buildkit/issues/1366 on windows hosts, you can either:
2+
# 1. Enable long file path support in windows
3+
# 2. Use the \\?\ prefix when specifying the path in the docker build command. e.g.
4+
# docker build \\?\C:\path -f .\Dockerfile
5+
# See https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
6+
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build-env
27

38
ARG MS_NUGET_URL=https://nuget.pkg.github.com/microsoft/index.json
49
ARG MSGRAPH_NUGET_URL=https://nuget.pkg.github.com/microsoftgraph/index.json
@@ -14,19 +19,34 @@ WORKDIR /app/msgraph-cli
1419
RUN dotnet nuget add source ${MS_NUGET_URL} -n ms-gh -u ${NUGET_USER} -p ${NUGET_PASSWORD} --store-password-in-clear-text &&\
1520
dotnet nuget add source ${MSGRAPH_NUGET_URL} -n msgraph-gh -u ${NUGET_USER} -p ${NUGET_PASSWORD} --store-password-in-clear-text
1621

17-
RUN dotnet publish ./src/msgraph-cli.csproj --configuration Release --no-self-contained -p:PublishSingleFile=false -p:PublishReadyToRun=false
22+
RUN dotnet publish -p:PublishSingleFile=false -p:PublishReadyToRun=true -p:PublishReadyToRunShowWarnings=true ./src/msgraph-cli.csproj --configuration Release --no-self-contained --runtime linux-musl-x64 --output /app/output
1823

19-
FROM mcr.microsoft.com/dotnet/runtime:6.0 as runtime
24+
FROM mcr.microsoft.com/dotnet/runtime:6.0-alpine as runtime
25+
26+
# Change this password by providing a different value when running the container
27+
ENV KEYRING_PASSWORD="password"
28+
29+
RUN apk add --no-cache libsecret dbus gnome-keyring libcap &&\
30+
dbus-uuidgen > /var/lib/dbus/machine-id &&\
31+
setcap cap_ipc_lock=+ep $(which gnome-keyring-daemon)
32+
33+
RUN addgroup mgc &&\
34+
adduser -D -G mgc -h /app mgc
2035

2136
WORKDIR /app
2237

23-
COPY --from=build-env /app/msgraph-cli/src/bin/Release/net6.0/ ./dist
24-
RUN echo 'export PATH=$PATH:/app/dist' > /app/.bash_profile
38+
COPY --from=build-env /app/output ./dist
39+
40+
RUN ln -s /app/dist/mgc /usr/bin/mgc
41+
42+
USER mgc
43+
44+
COPY --chown=mgc:mgc ./docker/* ./dist/
2545

26-
ENV HOME=/app
46+
RUN chmod +x /app/dist/init.sh
2747

2848
# CMD ["bash", "-l"]
29-
ENTRYPOINT ["/app/dist/mgc"]
49+
ENTRYPOINT ["./dist/init.sh"]
3050

3151
LABEL description="# Welcome to the Microsoft Graph CLI \
3252
[Source dockerfile](https://github.com/microsoftgraph/msgraph-cli/blob/main/Dockerfile)"

docker-compose.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: '2'
2+
services:
3+
mgc:
4+
image: msgraph-cli
5+
cap_add:
6+
# https://man7.org/linux/man-pages/man7/capabilities.7.html
7+
#
8+
- IPC_LOCK # Required by gnome-keyring daemon, the dbus secret service

docker/app-settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Debug"
5+
}
6+
}
7+
}

docker/init.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env sh
2+
3+
script="$0"
4+
DIR="$(dirname $script)"
5+
6+
if ! pgrep -x "dbus-daemon" > /dev/null
7+
then
8+
export DBUS_SESSION_BUS_ADDRESS=$(dbus-daemon --session --fork --print-address)
9+
else
10+
echo "dbus-daemon already running"
11+
fi
12+
13+
dbus-run-session -- echo "$KEYRING_PASSWORD" | gnome-keyring-daemon --daemonize --components=secrets --unlock && $@

msgraph-cli-core

src/Program.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,14 @@
88
using Microsoft.Graph.Cli.Core.Commands.Authentication;
99
using Microsoft.Graph.Cli.Core.Configuration;
1010
using Microsoft.Graph.Cli.Core.IO;
11-
using Microsoft.Graph.Cli.Core.Utils;
12-
using Microsoft.Kiota.Abstractions;
1311
using Microsoft.Kiota.Authentication.Azure;
1412
using Microsoft.Kiota.Cli.Commons.IO;
1513
using Microsoft.Kiota.Http.HttpClientLibrary;
16-
using Microsoft.Kiota.Http.HttpClientLibrary.Middleware;
17-
using Microsoft.Kiota.Http.HttpClientLibrary.Middleware.Options;
1814
using System.CommandLine;
1915
using System.CommandLine.Builder;
2016
using System.CommandLine.Hosting;
2117
using System.CommandLine.Parsing;
2218
using System.IO;
23-
using System.Linq;
24-
using System.Net.Http;
2519
using System.Reflection;
2620
using System.Threading.Tasks;
2721
using System.Collections.Generic;

src/app-settings.sample.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
{
22
"AuthenticationOptions": {
33
"ClientId": "client id",
4-
"TenantId": "tenant id"
4+
"TenantId": "tenant id",
5+
"AllowUnencryptedTokenCache": false
6+
},
7+
"Logging": {
8+
"LogLevel": {
9+
"Default": "Warning"
10+
}
511
}
612
}

0 commit comments

Comments
 (0)