The majority of dictionaries define this saying as, “A friend [to you when you are] in need is a friend indeed.” This proverb is often traced back to the Greek playwright Euripides in the fifth century BCE (“It is in trouble’s hour that the good most clearly show their friendship,” a citation approximately two centuries earlier than the others that have been mentioned in any of the answers or comments so far). The earliest examples of it in English, going back a thousand years, also follow this sense, and this is how most native speakers understand it.
The earliest surviving example of the in need/indeed rhyme might be the anonymous poem Everyman from the late 1400s, which has the dialogue,
“Sir, I say as I will do in deed.”
“Then be you a good friend at need;”
(This would not be correct grammar in modern English, but it was at the time.)
You should take heed, though, that (as one of the answers says), some native speakers interpret it as saying sarcastically that a friend who is in need will pretend to be a friend. This sentiment has been expressed in various ways for many centuries, too, but reading “a friend indeed” this way is modern. Back in the 1400s, “in deed” unambiguously meant that the friend’s actions matched their words, but “indeed” in modern English can be used as a disparaging intensifier.
Regardless of whether this is etymologically wrong, though, you should be aware that that is how some people will understand it.