Skip to content
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

Missing package libldap-2.4.so.2 at runtime:5.0-buster-slim #68365

Closed
brunobritodev opened this issue May 24, 2020 · 41 comments
Closed

Missing package libldap-2.4.so.2 at runtime:5.0-buster-slim #68365

brunobritodev opened this issue May 24, 2020 · 41 comments
Assignees
Labels
area-System.DirectoryServices enhancement Product code improvement that does NOT require public API changes/additions
Milestone

Comments

@brunobritodev
Copy link

Steps to reproduce the issue

  1. Create a .NET 5.0 Console app
  2. Run:
dotnet new nugetconfig
dotnet nuget add source -n dotnet5 https://dnceng.pkgs.visualstudio.com/public/_packaging/dotnet5/nuget/v3/index.json
  1. Get night build from System.DirectoryServices.Protocols, version 5.0.0-preview.6.20272.2
  2. Add the following code:
var credential = new NetworkCredential("<username>", "<password>");
var connection = new LdapConnection(new LdapDirectoryIdentifier("<ip(13.0.0.0)>", 389, false, false), credential);
connection.Bind();
  1. Run into container runtime:5.0-buster-slim
    Reference Dockerfile
FROM mcr.microsoft.com/dotnet/core/runtime:5.0-buster-slim AS base
RUN apt-get update && apt-get install -y libldap-2.4-2
WORKDIR /app

FROM mcr.microsoft.com/dotnet/core/sdk:5.0-buster AS build
WORKDIR /src
COPY ["TesteLdap/TesteLdap.csproj", "TesteLdap/"]
COPY ["nuget.config", "/src"]
RUN dotnet restore "TesteLdap/TesteLdap.csproj" --configfile "nuget.config"
COPY . .
WORKDIR "/src/TesteLdap"
RUN dotnet build "TesteLdap.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "TesteLdap.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "TesteLdap.dll"]

Expected behavior

Run without bugs

Actual behavior

We got this error at logs:
Unable to load shared library 'libldap-2.4.so.2' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibldap-2.4.so.2: cannot open shared object file: No such file or directory

Additional information (e.g. issue happens only occasionally)

The next version of System.DirectoryServices.Protocols has a dependency of libldap-2.4.
related to:

@MichaelSimons
Copy link
Member

@brunohbrito - Thanks for bringing this to our attention. There are a couple factors we consider when adding dependencies.

  1. How widely used are the scenarios that require the dependencies? The more generally the scenario, the more it makes sense to add the dependency.
  2. What is the size impact of adding the dependencies? In this case installing libldap-2.4.2 appears to add 1.64 MB to the buster-slim image.

@MichaelSimons MichaelSimons added area-dockerfiles enhancement Product code improvement that does NOT require public API changes/additions labels May 27, 2020
@brunobritodev
Copy link
Author

@MichaelSimons

There is any chance to Visual Studio identify which package is referenced during Add Docker Support from Solution Explorer? And auto add apt-get some required packages?

What do you think? So we can mitigate this kind of dependencies that isn't used on daily basis.

@MichaelSimons
Copy link
Member

@brunohbrito - I like the way you are thinking but I see a couple downfalls with the suggestion of making Add Docker Support handle adding the dependencies.

  1. It doesn't work for users who don't rely on the Add Docker Support functionality. Users are free to use other IDEs such as VSCode. Additionally there are VS users who have Dockerfiles managed outside of the Add Docker Support functionality.
  2. This implies the package references exist at the time Add Docker Support is used. What happens if the dependencies is added after the fact?

One path I lean towards is that when dependencies are missing, that the runtime self identifies and provides clear guidance for resolving.

@brunobritodev
Copy link
Author

@MichaelSimons

I thought something like this in .csproj:

<PackageReference Include="System.DirectoryServices.Protocols" Version="5.0.0-preview.6.20272.2">
    <Dependency So="Linux" Package="libldap-2.4.so.2"/>
</PackageReference>

Then Add Docker Support or any other extension, or even vscode plugins could use this information.
I'm not sure if it overkill, but it works.

@MichaelSimons
Copy link
Member

Copied comment from @richlander at dotnet/dotnet-docker#2004 (comment)

We have decided not to include this package in .NET container images, for any distro, and leaving it opt-in. This is due to the size impact. We consider the Directory Services API not to required by most containerized apps. We'd like feedback from folks that have other viewpoints.

@richlander
Copy link
Member

If we were to really invest in this, we'd get the NuGet package itself to carry the Linux package reference. The Linux package reference can be updated at any time. Carrying it in the project file isn't great. It also makes the project limited to one distro. Package names and versions are frequently not the same across distros (Debian vs Alpine) and same with versions (Debian 9 vs 10).

This is an overly constrained problem. If more people ask for help on this, we'll consider doing something better. However, it's hard.

@mthalman
Copy link
Member

cc @joperezr - Just an FYI that we've decided to not include the libldap package in our Docker images.

@mthalman
Copy link
Member

Closing this per the decision to not include the libldap package in the Docker images. Feel free to keep the discussion going.

@istretyakov
Copy link

I'm sorry, i didn't catch what is solution of this problem.
For example, i have .NET 5.0 in Docker. And how can i use System.DirectoryServices.Protocols for connecting to Active Directory? What and how need i install?
I understood that some libs there aren't in .NET Docker images, but how to get round the problem?

@mthalman
Copy link
Member

mthalman commented Apr 16, 2021

@istretyakov - You would need to install the appropriate LDAP library in your Dockerfile. Examples provided below.

Debian/Ubuntu:

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        libldap \
    && rm -rf /var/lib/apt/lists/*

Alpine:

RUN apk add --no-cache \
        libldap

@istretyakov
Copy link

@mthalman maybe i need to create other issue, it's a question for me. I try to send LDAP request from Docker container.
In Windows-case i get response that server is unavailable. It's right. This response shows that request was sent. In other environment (work) i get users. With Docker and without Docker, on Windows.
But in Linux-case (Docker) each time i have this exception: The LDAP server returned an unknown error. I can write not existed server and i will get this exception. It means that doesn't work. And i added installing lib in Dockerfile, yes.
One code, different reactions.
Maybe i lost something extra libs, except for libldap-2.4-2?

Windows:
Windows2

Linux:
Linux2

@mthalman
Copy link
Member

@istretyakov - It seems you've gotten past the missing dependencies, otherwise the errors would be about the library not being found. I would suggest filing a discussion post on your issue. Also, the LdapException should have an ErrorCode property that should provide the error code returned by the native LDAP library.

@adithyasai
Copy link

adithyasai commented Feb 19, 2022

I am getting the following error - Unable to load shared library 'libldap-2.4.so.2' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibldap-2.4.so.2: cannot open shared object file: No such file or directory

i am using the System.DirectoryServices.Protocols namespace for LdapConnection. have tried to install libldap in my docker image. in the following 3 ways but none of them worked.

RUN apt-get update && apt-get install libldap-2.4-2

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        libldap-2.4-2 \
    && rm -rf /var/lib/apt/lists/*

RUN apk add libldap

Here is my docker file

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        libldap-2.4-2 \
    && rm -rf /var/lib/apt/lists/*
WORKDIR /src
COPY ["Ldaptest1/Ldaptest1.csproj", "Ldaptest1/"]
RUN dotnet restore "Ldaptest1/Ldaptest1.csproj"
COPY . .
WORKDIR "/src/Ldaptest1"
RUN dotnet build "Ldaptest1.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Ldaptest1.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Ldaptest1.dll"]

i am getting the error in this line:
var connection = new LdapConnection(ldapDomain)

when trying to initiate LdapConnection class. can someone help me here?

@istretyakov
Copy link

@adithyasai i'm sorry, i don't remember, but I think i solved to use this library:
https://github.com/dsbenghe/Novell.Directory.Ldap.NETStandard
I wanted to use library from System's space, but there isn't solution of this problem.

@brunobritodev
Copy link
Author

@adithyasai i'm sorry, i don't remember, but I think i solved to use this library: https://github.com/dsbenghe/Novell.Directory.Ldap.NETStandard I wanted to use library from System's space, but there isn't solution of this problem.

Actually this is the best way to deal with LDAP. This component is extremely fast to connect and there are lot of options. It's a native implementation, while System's space use the Dll Import.

@mthalman
Copy link
Member

@adithyasai - Your Dockerfile is installing the package in a Dockerfile stage that's not being used when running your app. It's being installed in the build stage which is only used to build your project. That stage is not used when actually running the app.

Here's the suggested update:

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        libldap-2.4-2 \
    && rm -rf /var/lib/apt/lists/*

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["Ldaptest1/Ldaptest1.csproj", "Ldaptest1/"]
RUN dotnet restore "Ldaptest1/Ldaptest1.csproj"
COPY . .
WORKDIR "/src/Ldaptest1"
RUN dotnet build "Ldaptest1.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Ldaptest1.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Ldaptest1.dll"]

@durranitech
Copy link

The alpine docker image for dotnet 7 preview 1 runs on alpine 3.15 and that has libldap 2.6 so hitting this problem again. I have to install libldap 2.4 to get it to work. Any chance libldap 2.6 will be supported in future dotnet preview?

@mthalman
Copy link
Member

The alpine docker image for dotnet 7 preview 1 runs on alpine 3.15 and that has libldap 2.6 so hitting this problem again. I have to install libldap 2.4 to get it to work. Any chance libldap 2.6 will be supported in future dotnet preview?

@joperezr - Are you aware of any compat issues with libldap 2.6?

@joperezr
Copy link
Member

@joperezr - Are you aware of any compat issues with libldap 2.6?

I haven't looked into 2.5 or 2.6 yet. We decided to PInvoke directly into 2.4 because at the time we added support for it, 2.4 had been released for 10+ years and there wasn't any indication that a new one would ship. Looks like 2.5 and 2.6 were released in late 2021 and introduced primarily load balancing support as well as transaction support. I don't think there should be anything preventing us from using 2.5 or 2.6 as well if present, so to answer @durranitech question, I believe that it would be feasible to think that a future version of dotnet will support them. Could you please log an issue on dotnet/runtime about this so we can investigate, assign and prioritize this?

@mthalman
Copy link
Member

I believe that it would be feasible to think that a future version of dotnet will support them

@joperezr - We need to ensure this works across all supported .NET versions (3.1, 5.0, 6.0). This is related to dotnet/core#6985. In Alpine 3.15, libldap 2.6 is all that's available so we must support it.

@durranitech
Copy link

@joperezr should I still raise an issue for this or will this be looked at as part of the issue @mthalman referenced?

@ChrisHolcomb
Copy link

@adithyasai - Your Dockerfile is installing the package in a Dockerfile stage that's not being used when running your app. It's being installed in the build stage which is only used to build your project. That stage is not used when actually running the app.

Here's the suggested update:

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        libldap-2.4-2 \
    && rm -rf /var/lib/apt/lists/*

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["Ldaptest1/Ldaptest1.csproj", "Ldaptest1/"]
RUN dotnet restore "Ldaptest1/Ldaptest1.csproj"
COPY . .
WORKDIR "/src/Ldaptest1"
RUN dotnet build "Ldaptest1.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Ldaptest1.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Ldaptest1.dll"]

Did this work for anyone. I am having the same issue and tried the above but I'm still getting the same error

@richlander
Copy link
Member

I was just reading this again. After thinking about it (and also recently talking to the Docker Tools for VS folks about something else), I do think that a VS solution is an OK direction. I get the point that it doesn't work for everyone/all places, but providing a value-add in VS for this would be good. The same would be said about ICU and Alpine.

@ChrisHolcomb
Copy link

ChrisHolcomb commented Apr 7, 2022

So I finally did get this to work with the following docker file

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

RUN apt-get update \
    && apt-get install -y --no-install-recommends libldap-2.4-2 \
    && apt-get install -y --no-install-recommends libldap-common \
    && rm -rf /var/lib/apt/lists/* 
COPY ["Services/Identity/Identity.API/Certificate/ca_belcorpdc1.crt", "/usr/local/share/ca-certificates/"]
RUN chmod 644 /usr/local/share/ca-certificates/ca_belcorpdc1.crt && update-ca-certificates
COPY ["Services/Identity/Identity.API/Certificate/ldap.conf", "/etc/ldap/"] 

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["Services/Identity/Identity.API/Identity.API.csproj", "Services/Identity/Identity.API/"]
RUN dotnet restore "Services/Identity/Identity.API/Identity.API.csproj"
COPY . .
WORKDIR "/src/Services/Identity/Identity.API/"
RUN dotnet build "Identity.API.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Identity.API.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Identity.API.dll"]

I was still having issues with my connection not working with the cert so I add the libldap-common package and copied over a ldap.conf file that set the "TLS_REQCERT never", after that I was able to query the AD and authenticate users.

@anschauanderson
Copy link

anschauanderson commented Apr 18, 2022

I don't understand why you use this

COPY ["Services/Identity/Identity.API/Certificate/ca_belcorpdc1.crt", "/usr/local/share/ca-certificates/"]
RUN chmod 644 /usr/local/share/ca-certificates/ca_belcorpdc1.crt && update-ca-certificates
COPY ["Services/Identity/Identity.API/Certificate/ldap.conf", "/etc/ldap/"]

Where you get ca_belcorpdc1.crt?

@ChrisHolcomb
Copy link

Our system admin gave me the certificate so I copied to the project and this puts the certificate into the container and tells it to update it's certificates list.

@anschauanderson
Copy link

I have this error, Can you tell me what it could be?

System.DllNotFoundException: Unable to load shared library 'ldap.so.2' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libldap.so.2: cannot open shared object file: No such file or directory
at LdapForNet.Native.NativeMethodsLinux.ldap_initialize(IntPtr& ld, String uri)
at LdapForNet.Native.LdapNativeLinux.Init(IntPtr& ld, String url)
at LdapForNet.LdapConnection.Connect(String url, LdapVersion version)
at LdapForNet.LdapConnectExtensions.Connect(ILdapConnection connection, Uri uri, LdapVersion version)
at LdapForNet.LdapConnectExtensions.Connect(ILdapConnection connection, String hostname, Int32 port, LdapSchema ldapSchema, LdapVersion version)
at Inlog.Fiscol.Domain.CommandHandlers.Account.LogarUsuarioCommandHandler.AuthenticateADUser(String userName, String password) in /src/Inlog.Fiscol.Domain/CommandHandlers/Account/LogarU

@ChrisHolcomb
Copy link

It looks like your container does not have the ldap library, That is what the RUN apt-get commands are for, they install it on the linux container.

Add
RUN apt-get update
&& apt-get install -y --no-install-recommends libldap-2.4-2
&& apt-get install -y --no-install-recommends libldap-common
&& rm -rf /var/lib/apt/lists/*
to install the libraries. This needs to be installed on the base image which is used in the final build step.

@anschauanderson
Copy link

anschauanderson commented Apr 18, 2022

It's not working for me.

My Dockerfile

FROM mcr.microsoft.com/dotnet/aspnet:6.0-focal-amd64 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

RUN apt-get update
&& apt-get install -y --no-install-recommends libldap-2.4-2
&& apt-get install -y --no-install-recommends libldap-common
&& rm -rf /var/lib/apt/lists/*

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build

WORKDIR /src
COPY ["Inlog.Fiscol.Api/Inlog.Fiscol.Api.csproj", "Inlog.Fiscol.Api/"]
RUN dotnet restore -s "http://inlog-nuget-server.azurewebsites.net/nuget/" -s "https://api.nuget.org/v3/index.json" "Inlog.Fiscol.Api/Inlog.Fiscol.Api.csproj"
COPY . .
WORKDIR "/src/Inlog.Fiscol.Api"
RUN dotnet build "Inlog.Fiscol.Api.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Inlog.Fiscol.Api.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Inlog.Fiscol.Api.dll"]

@sameerbaveja
Copy link

@ChrisHolcomb Can you please show your ldap.conf file. Below is my docker & its not working for me.

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM misnexusprd.corp.amdocs.com/microsoft-proxy/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM misnexusprd.corp.amdocs.com/microsoft-proxy/dotnet/sdk:5.0 AS build
WORKDIR /src

RUN apt-get update
&& apt-get install -y --no-install-recommends libldap-2.4-2
&& apt-get install -y --no-install-recommends libldap-common
&& rm -rf /var/lib/apt/lists/*

COPY ./ResetPassword.WebAPI/ldap.conf /etc/ldap/

COPY ./ResetPassword.WebAPI/Amdocs_Root_Certification_Authority.crt /etc/ssl/certs/
COPY ./ResetPassword.WebAPI/AmdocsClass3SecureServerCA.crt /etc/ssl/certs/
COPY ./ResetPassword.WebAPI/amdocs.pem /etc/ssl/certs/
COPY NuGet.Config /root/.nuget/NuGet/NuGet.Config

RUN update-ca-certificates
COPY ["./ResetPassword.WebAPI/ResetPassword.WebAPI.csproj", "ResetPassword.WebAPI/"]
COPY ["./ResetPassword.Core/ResetPassword.Core.csproj", "ResetPassword.Core/"]
RUN dotnet restore "ResetPassword.WebAPI/ResetPassword.WebAPI.csproj"
COPY . .
WORKDIR "/src/ResetPassword.WebAPI"
RUN dotnet build "ResetPassword.WebAPI.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "ResetPassword.WebAPI.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ResetPassword.WebAPI.dll"]

@ChrisHolcomb
Copy link

ChrisHolcomb commented Apr 19, 2022

this is my ldap.conf file

# LDAP Defaults
#

# See ldap.conf(5) for details
# This file should be world readable but not world writable.

#BASE	dc=example,dc=com
#URI	ldap://ldap.example.com ldap://ldap-master.example.com:666

#SIZELIMIT	12
#TIMELIMIT	15
#DEREF		never
#TLS_REQCERT	demand
TLS_REQCERT	never

@sameerbaveja
Copy link

@ChrisHolcomb Its still not working for me :(

I am getting below error :

Unexpected error: System.DllNotFoundException: Unable to load shared library 'libldap-2.4.so.2' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibldap-2.4.so.2: cannot open shared object file: No such file or directory\n at Interop.Ldap.ldap_get_option_int(IntPtr ldapHandle, LdapOption option, Int32& outValue)\n at Interop.Ldap..cctor()

Below is my docker :

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
expose 443

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src

RUN apt-get update
&& apt-get install -y --no-install-recommends libldap-2.4-2
&& apt-get install -y --no-install-recommends libldap-common
&& rm -rf /var/lib/apt/lists/*

COPY ./ResetPassword.WebAPI/ldap.conf /etc/ldap/

COPY ./ResetPassword.WebAPI/Amdocs_Root_Certification_Authority.crt /etc/ssl/certs/
COPY ./ResetPassword.WebAPI/AmdocsClass3SecureServerCA.crt /etc/ssl/certs/
COPY ./ResetPassword.WebAPI/amdocs.pem /etc/ssl/certs/
COPY NuGet.Config /root/.nuget/NuGet/NuGet.Config
RUN update-ca-certificates

COPY ["ResetPassword.WebAPI/ResetPassword.WebAPI.csproj", "ResetPassword.WebAPI/"]
COPY ["ResetPassword.Core/ResetPassword.Core.csproj", "ResetPassword.Core/"]
RUN dotnet restore "ResetPassword.WebAPI/ResetPassword.WebAPI.csproj"
COPY . .
WORKDIR "/src/ResetPassword.WebAPI"
RUN dotnet build "ResetPassword.WebAPI.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "ResetPassword.WebAPI.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ResetPassword.WebAPI.dll"]

@anschauanderson
Copy link

I changed lib,

Now i am using Novell.Directory.Ldap.NETStandard and it's working for me to connect at Active Derectory From Docker / Linux;

@sameerbaveja
Copy link

Can you send me the code to connect to AD & search for a user attributes.

@anschauanderson
Copy link

private bool AuthenticateADUser(string userName, string password)
        {
            bool ret = false;

            try
            {
                using (var cn = new Novell.Directory.Ldap.LdapConnection())
                {
                    // Ldap URL, in my case 10.150.16.12
                    cn.Connect(_"10.150.16.12", 389);
                    // This is necessary username@domain ex. anderson@inlog
                    cn.Bind(userName + "@inlog", password);
                    ret = true;
                }

            }
            catch (Exception x)
            {
                Console.WriteLine(x.ToString());
                ret = false;
            }

            return ret;
        }

@ChrisHolcomb
Copy link

@ChrisHolcomb Its still not working for me :(

I am getting below error :

Unexpected error: System.DllNotFoundException: Unable to load shared library 'libldap-2.4.so.2' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibldap-2.4.so.2: cannot open shared object file: No such file or directory\n at Interop.Ldap.ldap_get_option_int(IntPtr ldapHandle, LdapOption option, Int32& outValue)\n at Interop.Ldap..cctor()

Below is my docker :

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base WORKDIR /app EXPOSE 80 expose 443

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build WORKDIR /src

RUN apt-get update && apt-get install -y --no-install-recommends libldap-2.4-2 && apt-get install -y --no-install-recommends libldap-common && rm -rf /var/lib/apt/lists/*

COPY ./ResetPassword.WebAPI/ldap.conf /etc/ldap/

COPY ./ResetPassword.WebAPI/Amdocs_Root_Certification_Authority.crt /etc/ssl/certs/ COPY ./ResetPassword.WebAPI/AmdocsClass3SecureServerCA.crt /etc/ssl/certs/ COPY ./ResetPassword.WebAPI/amdocs.pem /etc/ssl/certs/ COPY NuGet.Config /root/.nuget/NuGet/NuGet.Config RUN update-ca-certificates

COPY ["ResetPassword.WebAPI/ResetPassword.WebAPI.csproj", "ResetPassword.WebAPI/"] COPY ["ResetPassword.Core/ResetPassword.Core.csproj", "ResetPassword.Core/"] RUN dotnet restore "ResetPassword.WebAPI/ResetPassword.WebAPI.csproj" COPY . . WORKDIR "/src/ResetPassword.WebAPI" RUN dotnet build "ResetPassword.WebAPI.csproj" -c Release -o /app/build

FROM build AS publish RUN dotnet publish "ResetPassword.WebAPI.csproj" -c Release -o /app/publish

FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "ResetPassword.WebAPI.dll"]

That won't work. You are installer the library in the Build container not the Base container.

@richlander richlander reopened this Apr 22, 2022
@richlander
Copy link
Member

richlander commented Apr 22, 2022

This issue is still getting significant activity. I propose we update the error message, like the following:

Unable to load shared library 'libldap-2.4.so.2' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibldap-2.4.so.2: cannot open shared object file: No such file or directory

See https://aka.ms/dotnet/ldap-dependency to learn more.

From a container standpoint, I think think we made the best choice, to not install the ldap component. However, we need to do more to make this dependency problem self-diagnosable.

Also, this document doesn't make any mention of a dangling dependency: https://docs.microsoft.com/dotnet/api/system.directoryservices.protocols.ldapconnection.

Related, this dependency likely isn't constant across all distros. We should capture that somewhere, possibly at https://github.com/dotnet/core/blob/main/release-notes/6.0/linux-packages.md.

/cc @joperezr

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Apr 22, 2022
@richlander richlander transferred this issue from dotnet/dotnet-docker Apr 22, 2022
@sameerbaveja
Copy link

@ChrisHolcomb I tried what you suggested. Now i am not getting DLL error.

New Error: The feature is not supported.

Code :

        LdapDirectoryIdentifier ldi = new LdapDirectoryIdentifier("", 389, true, false);
        LdapConnection lc = new LdapConnection(ldi);
        lc.AuthType = AuthType.Kerberos;
        lc.Bind(new System.Net.NetworkCredential("", "", ""));
        string filter = String.Format("(&(objectCategory=person)(EmployeeID={0}))", empId);
        string[] attributesToReturn = { "samaccountName", "lockoutTime", "givenname", "sn", "EmployeeID" };
        SearchRequest sreq = new SearchRequest("", filter, System.DirectoryServices.Protocols.SearchScope.Subtree, attributesToReturn);
        SearchResponse sres = lc.SendRequest(sreq) as SearchResponse;

Docker :

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM misnexusprd.corp.amdocs.com/microsoft-proxy/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

RUN apt-get update
&& apt-get install -y --no-install-recommends libldap-2.4-2
&& apt-get install -y --no-install-recommends libldap-common
&& rm -rf /var/lib/apt/lists/*

COPY ./ResetPassword.WebAPI/DC2.cert.cer /usr/local/share/ca-certificates/
RUN chmod 644 /usr/local/share/ca-certificates/DC2.cert.cer && update-ca-certificates
COPY ./ResetPassword.WebAPI/ldap.conf /etc/ldap/

FROM misnexusprd.corp.amdocs.com/microsoft-proxy/dotnet/sdk:5.0 AS build
WORKDIR /src

COPY ./ResetPassword.WebAPI/Amdocs_Root_Certification_Authority.crt /etc/ssl/certs/
COPY ./ResetPassword.WebAPI/AmdocsClass3SecureServerCA.crt /etc/ssl/certs/
COPY ./ResetPassword.WebAPI/amdocs.pem /etc/ssl/certs/
RUN update-ca-certificates
COPY NuGet.Config /root/.nuget/NuGet/NuGet.Config

COPY ["./ResetPassword.WebAPI/ResetPassword.WebAPI.csproj", "ResetPassword.WebAPI/"]
COPY ["./ResetPassword.Core/ResetPassword.Core.csproj", "ResetPassword.Core/"]
RUN dotnet restore "ResetPassword.WebAPI/ResetPassword.WebAPI.csproj"
COPY . .
WORKDIR "/src/ResetPassword.WebAPI"
RUN dotnet build "ResetPassword.WebAPI.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "ResetPassword.WebAPI.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ResetPassword.WebAPI.dll"]

@ghost
Copy link

ghost commented Apr 22, 2022

Tagging subscribers to this area: @dotnet/area-system-directoryservices, @jay98014
See info in area-owners.md if you want to be subscribed.

Issue Details

Steps to reproduce the issue

  1. Create a .NET 5.0 Console app
  2. Run:
dotnet new nugetconfig
dotnet nuget add source -n dotnet5 https://dnceng.pkgs.visualstudio.com/public/_packaging/dotnet5/nuget/v3/index.json
  1. Get night build from System.DirectoryServices.Protocols, version 5.0.0-preview.6.20272.2
  2. Add the following code:
var credential = new NetworkCredential("<username>", "<password>");
var connection = new LdapConnection(new LdapDirectoryIdentifier("<ip(13.0.0.0)>", 389, false, false), credential);
connection.Bind();
  1. Run into container runtime:5.0-buster-slim
    Reference Dockerfile
FROM mcr.microsoft.com/dotnet/core/runtime:5.0-buster-slim AS base
RUN apt-get update && apt-get install -y libldap-2.4-2
WORKDIR /app

FROM mcr.microsoft.com/dotnet/core/sdk:5.0-buster AS build
WORKDIR /src
COPY ["TesteLdap/TesteLdap.csproj", "TesteLdap/"]
COPY ["nuget.config", "/src"]
RUN dotnet restore "TesteLdap/TesteLdap.csproj" --configfile "nuget.config"
COPY . .
WORKDIR "/src/TesteLdap"
RUN dotnet build "TesteLdap.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "TesteLdap.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "TesteLdap.dll"]

Expected behavior

Run without bugs

Actual behavior

We got this error at logs:
Unable to load shared library 'libldap-2.4.so.2' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibldap-2.4.so.2: cannot open shared object file: No such file or directory

Additional information (e.g. issue happens only occasionally)

The next version of System.DirectoryServices.Protocols has a dependency of libldap-2.4.
related to:

Author: brunohbrito
Assignees: -
Labels:

enhancement, area-System.DirectoryServices, untriaged, area-dockerfiles

Milestone: -

@joperezr joperezr self-assigned this May 4, 2022
@joperezr joperezr added this to the 7.0.0 milestone May 4, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label May 4, 2022
@joperezr
Copy link
Member

This is now a dupe of #69456 as I believe that once that one is fixed (support libldap 2.x versions) then this issue will be resolved. Closing this issue in favor of that one which we are tracking for 7.0.

@ghost ghost locked as resolved and limited conversation to collaborators Aug 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.DirectoryServices enhancement Product code improvement that does NOT require public API changes/additions
Projects
None yet
Development

No branches or pull requests